Generic type information is not available at runtime in Java for backwards compatibility reasons.
What exactly compatibility reasons mean here? Also is generic type information available in some cases or is it ALWAYS unavailavble and are there any other reasons than backwards compatibility?
I have some knowledge about it but I would like to finally understand it if anyone would be kind enough to answer this question. I have read read several articles and bits of Oracle documentation but they weren't focused on the problem I'm trying to figure out here.
Type information is always erased. Imagine you have a set of strings, you would (now) use Set<String> - but before generics were added it would be simply Set. To ensure backwards compatibility when generics were added to Java (in 2004 with J2SE 5.0) the type information is removed. So Set<String> compiles to Set to allow compatibility with code written before generics were added.
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