The following code fails when the constructor parameter is declared with val
Works:
class Poso(array : Array[_ <: Any])
object Test {
new Poso(classOf[Retention].getEnumConstants())
}
Doesn’t work:
class Poso(val array : Array[_ <: Any])
object Test {
new Poso(classOf[Retention].getEnumConstants())
}
The compiler gives the error:
Error in Scala compiler: type mismatch; found :java.lang.Object required: array[java.lang.Object]
Without being able to give a line number.
Looks like a bug in Scala compiler (it dies on an exception). You should probably report it to Scala developers.
Using
AnyRefinstead ofAnyfixed it for me: