You know, like the CLR does. Is anyone even admitting the lack of runtime generic information is a problem, and working to solve it?
The designers of Java opted for this solution to maintain backward compatibility (on the bytecode level). Since then, there is even more Java code out there, thus breaking backward compatibility would have ever worse consequences. So I doubt they would change their minds about this.
Why is this a problem (from the comments to your question)
Well, consider for instance that can't overload a method like this:
void foo(List<String> strings) { ... }
void foo(List<Integer> ints) { ... }
even though it makes sense to actually allow this. (The main reason why this doesn't work today, is because it would, when compiled to bytecode, look like foo(List strings)
and foo(List ints)
.)
Are there any plans for the JVM to support generics at runtime?
According to this page it's at least not in the pipe-line for Java 7:
Reified Generics
Currently, generics are implemented using erasure, which means that the generic type information is not available at runtime, which makes some kind of code hard to write. Generics were implemented this way to support backwards compatibility with older non-generic code. Reified generics would make the generic type information available at runtime, which would break legacy non-generic code. However, Neal Gafter has proposed making types reifiable only if specified, so as to not break backward compatibility.
Links
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With