Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(new Array[AnyRef](5)).asInstanceOf[Array[T]] warning #234

Open
VladUreche opened this issue Jun 5, 2015 · 1 comment
Open

(new Array[AnyRef](5)).asInstanceOf[Array[T]] warning #234

VladUreche opened this issue Jun 5, 2015 · 1 comment
Assignees
Milestone

Comments

@VladUreche
Copy link
Member

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!

@VladUreche
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants