blob: 4d934a9a164d451ad20f8bd8c54efd14b5bcf34b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
class A[+T] {
val foo0 = {
class AsVariantAsIWantToBe { def contains(x: T) = () }
new AsVariantAsIWantToBe
}
def foo1 = {
class VarianceIsTheSpiceOfTypes { def contains(x: T) = () }
new VarianceIsTheSpiceOfTypes
}
}
object Test {
def main(args: Array[String]): Unit = {
val xs: A[String] = new A[String]
println(xs.foo0 contains "abc")
println((xs: A[Any]).foo0 contains 5)
// java.lang.NoSuchMethodException: A$AsVariantAsIWantToBe$1.contains(java.lang.String)
}
}
|