trait X { def append[-](): Unit }
为什么可以编译?我的意思是[ – ]很奇怪
class Y { def identity[-](x: -): - = x } (new Y).identity(5) // returns 5
– []这里是一个普通的类型名称,就像 – 作为以下代码中的类名:
class -
请注意,因为方法的类型参数不能标记为逆变,所以编译器不会将 – 解释为 – 表示逆变.另一方面,这不会解析:
class Z[-] {}