Skip to content

ClassCastException for generic array construction #4037

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

Closed
allanrenucci opened this issue Feb 26, 2018 · 0 comments
Closed

ClassCastException for generic array construction #4037

allanrenucci opened this issue Feb 26, 2018 · 0 comments

Comments

@allanrenucci
Copy link
Contributor

allanrenucci commented Feb 26, 2018

import scala.reflect.ClassTag

object Main {
  def foo[T <: AnyRef : ClassTag] = new Array[T](42)
  def main(args: Array[String]): Unit = {
    val x: Array[String] = foo[String]
  }
}
> dotc Main.scala
> dotr Main
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
	at Main$.main(Main.scala:6)
	at Main.main(Main.scala)
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