miniboxing-plugin
miniboxing-plugin copied to clipboard
(new Array[AnyRef](5)).asInstanceOf[Array[T]] warning
The dirtiest one of all:
$ mb-scala
Welcome to Scala version 2.11.6-20150224-172222-092690e7bf (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_80).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def foo[@miniboxed T] = new Array[AnyRef](5).asInstanceOf[Array[T]]
foo: [T]=> Array[T]
Warn, and the second time it happens, run sudo rm -rf /
on the guys machine!
To explain why it's the dirtiest one of all:
$ mb-scala
Welcome to Scala version 2.11.6-20150224-172222-092690e7bf (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_80).
Type in expressions to have them evaluated.
Type :help for more information.
scala> def foo[@miniboxed T] = new Array[AnyRef](5).asInstanceOf[Array[T]]
foo: [T]=> Array[T]
scala> foo[Int](0) = 5
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [I
... 33 elided