Skip to content

Instantly share code, notes, and snippets.

View ostretsov's full-sized avatar
🏠
Working from home

Artem Ostretsov ostretsov

🏠
Working from home
View GitHub Profile
class Animal
trait Furry extends Animal
trait HasLegs extends Animal
class Cat extends Animal with Furry with HasLegs
class Dog extends Furry with HasLegs
class Dog with Furry with HasLegs // won't work
class Animal
trait Furry extends Animal
trait HasLegs extends Animal
class Rectangle(width: Int, height: Int) {
def getWidth: Int = width
def getHeight: Int = height
}
class Square(side: Int) extends Rectangle(side, side) {
def getSomething: Int = 1
}
def area(rectangle: Rectangle): Int = {
rectangle.getHeight * rectangle.getWidth * rectangle.getSomething // it would't work!
class Rectangle(width: Int, height: Int) {
def getWidth(): Int = width
def getHeight(): Int = height
}
class Square(side: Int) extends Rectangle(side, side)
def area(rectangle: Rectangle): Int = {
rectangle.getHeight() * rectangle.getWidth()
}
class Rectangle(width: Int, height: Int)
class Square(side: Int) extends Rectangle(side, side)
val s = new Square(5)
<?php
/**
* (c) Artem Ostretsov <artem@ostretsov.ru>
* Created at 15.10.2014 12:31
*/
namespace SP\EventBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
<?php
/**
* (c) Artem Ostretsov <artem@ostretsov.ru>
* Created at 15.10.2014 12:32
*/
namespace SP\EventBundle\Validator\Constraints;
use SP\EventBundle\Entity\EventRequest;
class A(l: Int) {
private val length = l
}
class AMinified (private val length: Int) // avoid code smell
def f1() = 1
def f2 = 2
f1()
f1
// f2() // it doesn't work as expected!
f2
def f1(x: Int, y: Int) = x + y
def f2(x: Int)(y: Int) = x + y
println(f1(1, 2))
println(f2(1) {
val a = 5
val b = 6
a + b
})