Are there any JVM support plans to support run-time generics?

You know how the CLR does it. Does anyone even acknowledge the lack of general information about the runtime, is a problem and is working to solve it?

+7
java generics
source share
4 answers

Java designers decided to use this solution for backward compatibility (at the bytecode level). Since then there has been even more Java code, so breaking backward compatibility will have increasingly serious consequences. Therefore, I doubt that they changed their mind about this.

+3
source share

Why is this a problem (from comments on your question)

Well, consider, for example, that this method cannot overload:

void foo(List<String> strings) { ... } void foo(List<Integer> ints) { ... } 

although it makes sense to actually allow it. (The main reason why this doesn't work today is because when compiled to bytecode, it looks like foo(List strings) and foo(List ints) .)

Are there any JVM plans to support generics at run time?

According to this page , at least this is not a line for Java 7:

Reified Generics

Currently, generic tools are implemented using erasure, which means that general type information is not available at runtime, making it difficult to write some code. These tools were implemented in such a way as to maintain backward compatibility with old custom code. Reasonable generic files will provide information about the common type at runtime, which will lead to the loss of obsolete non-shared code. However, Neil Gufter suggested making types re-accessible only if they are specified so as not to violate backward compatibility.

References

+2
source share

I believe that someone (possibly Mark Reinhold) told JavaOne this year that they might try to repeat Java generalizations in the future. This, of course, would not be earlier than Java 9, and it would be a huge change with a lot of potential problems to be developed.

+1
source share

The problem can be partially solved without changing the JVM: in Scala (also running on the JVM), you can add the so-called Manifests , which contain information such as runtime for general parameters. I think this solution can be adapted for Java without any problems. This is not ideal, but it is probably much easier to implement as the “real thing”.

0
source share

All Articles