How does Guice\'s TypeLiteral overcome the Java generic types erasure procedure?
It works wonders but how is this accomplished?
The trick that is used here is that the signatures of generic super types are stored in subclasses and thus survive erasure.
If you create an anonymous subclass new TypeLiteral
Guice can call getClass().getGenericSuperclass() on it and get a java.lang.reflect.ParameterizedType on which exists a method getActualTypeArguments() to get >() {}
List
as an instance of ParameterizedType
.