The erasure type means that information about the general type of the object is simply not available at run time.
(Link to the corresponding section of Angelika Langer Java Generics Frequently Asked Questions , which should answer almost every question you could ask about Java generics:)
- . , , , :)
, . :
import java.lang.reflect.*;
import java.util.*;
public class Test
{
public List<String> names;
public static void main(String [] args)
throws Exception
{
Field field = Test.class.getDeclaredField("names");
ParameterizedType type = (ParameterizedType) field.getGenericType();
System.out.println(type.getRawType());
for (Type typeArgument : type.getActualTypeArguments())
{
System.out.println(" " + typeArgument);
}
}
}
T List<T>, , .
- . , - :
public class StringCollection implements Collection<String>
StringCollection, . getGenericSuperType getGenericInterfaces , , .
, . , , .