3 ms·
The key thing to remember is that generics are just for the compiler. There isn't anything actually embedded in the bytecode that knows what type a generic is.
by narrator 12y ago
The key thing to remember is that generics are just for the compiler. There isn't anything actually embedded in the bytecode that knows what type a generic is.
- nicobn 12y agoThis is only partially true. Generic types are accessible through the reflection API. What you are referring to is type erasure. See for yourself: https://gist.github.com/nicobn/8135faeda058fef5b6b9 https://gist.github.com/nicobn/8135faeda058fef5b6b9
- slantedview 12y agoGenerics are captured in various places in bytecode - most importantly in type definitions. This is how the common type token pattern is exploited. Where generics are erased is in local variable declarations.