val animal: Animal = new Cat
((animal: Animal) => {}) apply new Cat
class Cat extends Animal {
override def eat(food: Animal): Animal = food
}
val animal: Animal = new Cat
((animal: Animal) => {}) apply new Cat
final class Array[T] extends ...
public class Unsafe{
public static void main(String[] args){
String[] a = new String[1];
Object[] b = a;
b[0] = 1; // HERE!
System.out.println(b[0]);
}
}
sealed abstract class List[+A] extends ...
val animals: List[Animal] = List(new Cat)
sealed abstract class List[+A] extends ...
val what: List[Any] = 1 :: "hey" :: List()
val cats: List[Cat] = List(new Cat)
cats.contains(1) // false
sealed abstract class List[+A] extends ...
def contains(elem: Any): Boolean
val cat: Cat = null
val cats: List[Cat] = List(null)
null.isInstanceOf[Cat] // false
class Cat extends Animal {
override def eat(food: Animal): Animal = food
}
class Animal {
def self: Animal = this }
class Cat extends Animal {
override
def self: Cat = this }
val a1: Animal = new Cat
val a2: Animal = a1.self
val c1: Cat = new Cat
val c2: Cat = c1.self
class Animal {
def eat(food: Animal): Unit = () }
class Cat extends Animal {
override // Error: override nothing
def eat(food: Object): Unit = () }
(new Cat).eat(new Object)
val f: Function1[Cat, Animal] =
(a: Animal) => new Cat
a > a
- > +
val f: Function1[Cat, Animal] =
(a: Animal) => new Cat
f :: Cat -> Animal
f = (\animal -> Cat) :: Animal -> Cat
trait Function1[-T, +R] extends AnyRef
.(a, a) > a
-(a, a) > +
.(-, -) > +
trait Function2[-T1, -T2, +R] extends AnyRef
a > (a > a)
- > (- > +)
trait Function1[-T1, Function1[-T2, +R]]
.(a > a)>a
-(- > +)>+
.(+ > -)>+
val f: Function1[Function1[Animal, Cat], Animal] =
(g: Function1[Cat, Animal]) => new Cat
+ -> - -> +