Why do Java Anonymous Classes retain generic information at runtime?

50 Views Asked by At

While I was looking for a way to retain information about generic types at runtime in the context of JSON (de)serialization with Jackson, I found out that it's indeed possible to do so using TypeReference<T>.
I then wanted to understand how and why it works, so I followed the link in the documentation, which leads here.

I understand that there are some circumstances, such as with anonymous inner classes, where it is possible to know the generic type of a class even at runtime (I think it can be said the type erasure does not fully apply here), but I don't understand why : why bother adding this (fairly obscure) feature if it is only appliable to this particular case? Don't get me wrong, it is fairly handy to have it, but why does it exist in the first place?

0

There are 0 best solutions below