4 ms·
> but AFAIK the Java compiler throws away any type information from the source code You're thinking about generics. .class files preserve a whole bunch of type
by pdpi 7y ago
> but AFAIK the Java compiler throws away any type information from the source code
You're thinking about generics. .class files preserve a whole bunch of type information (I'm building a .class decompiler in my free time, and I'm looking at that very same data in my debugger ATM).
- The_Colonel 7y agoYou probably know this, but it's not obvious to the random reader. Even generic types are available in the Java .class file and are accessible from the reflection API. Spring for example uses this quite heavily.
- cogman10 7y agoIt depends on where you are at. Type information is present in fields and class inheritance For example, a class like this `class Foo implements Bar<String>` Retains the fact that the generic type is a String. That information is completely lost at method invocation. So a method that takes a `Bar<String>` ultimately compiles to a method that takes a `Bar` and knows nothing of the String. To get that generic information down you have to engage in some fun tricks using either the class or field method I mentioned earlier. (Usually you do this with a second type parameter where it matters).