一. 操作符 自定义操作符 操作付默认左结合调用.除了以:结尾的操作符是右结合调用 object OperaterTest extends App{ val a: myInt = new myInt(1) val b: myInt = new myInt(2) val c: myInt = new myInt(3) println(a +++ b) println((c---:b---:a).value) //:结尾的操作符右结合,相当于(a.---:(b)).---:(c) = 1-2-3 }…
协变 案例一: class Animal {} class Bird extends Animal {} class Animal {} class Bird extends Animal {} //协变 class Covariant[T](t:T){} val cov = new Covariant[Bird](new Bird) val cov2:Covariant[Animal] = cov c不能赋值给c2,因为Covariant定义成不变类型. 稍微改一下: class Animal…