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
getClass() return java.lang.Class[T] forSome { val T : C } #490
Comments
Imported From: https://issues.scala-lang.org/browse/SI-490?orig=1 |
@SethTisue said: |
Lauri Alanko (lealanko) said: scala> classOf[List[int]]
res4: java.lang.Class[List[int]] = class scala.List
scala> classOf[List[String]]
res5: java.lang.Class[List[String]] = class scala.List That is, the type system claims that the class object is a representation of a type application, even though there is no real run-time information about the type argument. I think it would be desirable for the property to hold that if So I suggest that classOf[List[A]] : Class[List[T] forSome { type T }] |
@SethTisue said: |
Commit Message Bot (anonymous) said: def f1 = 5.getClass // Class[Int] class A def f1 = (new B: Any).getClass().newInstance() // Any But that's not all! def f0[T >: B] = (new B: T).getClass().newInstance() def f5 = f0[Any] // Any Closes #490, #896, #4696. Review by moors. (Note: I think this is |
It would be useful if Scala were to treat the return from getClass() as
a java.lang.Class[T] forSome { val T : C } where C is something like the
erasure of the static type of the expression on which getClass is called.
This would match Java 6:
http://java.sun.com/javase/6/docs/api/java/lang/Object.html#getClass()
It would let me do something like the following where I want to introspect
on a class but shouldn't need a class instance. I also want to limit the
types of classes I want to introspect on, so I use Class[_ <: Foo]. But
this prevents me from passing in a Foo class by using Foo.getClass()
without a cast.
There was a request for this and Martin responded:
http://scala-programming-language.1934581.n4.nabble.com/Java-generics-vs-Scala-types-td1937960.html
The text was updated successfully, but these errors were encountered: