Closed
Description
JA.java
:
class JA {
public static <T> T get(T[] arr) {
return arr[0];
}
}
Compat.scala
:
object Compat {
def main(args: Array[String]): Unit = {
val x = new Array[Int](1)
x(0) = 10
println(JA.get(x))
}
}
This should output an error since T[]
is erased to Object[]
but it compiles fine, for comparison, scalac
will complain with:
Compat.scala:5: error: type mismatch;
found : Array[Int]
required: Array[? with Object]
Note: Int >: ? with Object, but class Array is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: ? with Object`. (SLS 3.2.10)
println(JA.get(x))
^
one error found