Type erasure is supposed to erase all generic information…
If this is the case how does a library like GSON use generics to determine what type to deserialize to?
e.g.
private Map<String,Date> tenordates;
This will deserialize to <String,Date>
where as
private Map<Date,Date> tenordates;
will deserialize to <Date,Date>
so somehow its using the generic info at runtime.
Type erasure does not erase all type information. It does not delete it from class, field, return type and parameter definitions. The type information in the following examples is retained:
This is accesible via reflection – the
java.lang.reflect.ParameterizedType. You can check whether a givenTypeisinstanceofthat class, cast to it and obtain the type information.