What are Reified Generics? How do they solve Type Erasure problems and why can’t they be added without major changes?

The whole point is that reified generics have support in the compiler for preserving type information, whereas type erased generics don’t. AFAIK, the whole point of having type erasure in the first place was to enable backwards compatibility (e.g. lower versioned JVMs could still understand generic classes).

You can explicitly add the type information in the implementation, as you have above, but that requires additional code every time the list is used, and is pretty messy in my opinion. Also, in this case, you still don’t have runtime type checking for all of the list methods unless you add the checks yourself, however reified generics will ensure the runtime types.

Leave a Comment