Java Tutorial/Reflection/Generic — различия между версиями
Admin (обсуждение | вклад) м (1 версия)  | 
				|
(нет различий) 
 | |
Версия 17:44, 31 мая 2010
Generic class Reflection
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
import java.util.ArrayList;
import java.util.List;
public class GenericReflect {
  public static void main(String[] args) {
    TypeVariable[] tv = List.class.getTypeParameters();
    System.out.println(tv[0].getName()); // E
    class StringList extends ArrayList<String> {
    }
    Type type = StringList.class.getGenericSuperclass();
    System.out.println(type); 
    ParameterizedType pt = (ParameterizedType) type;
    System.out.println(pt.getActualTypeArguments()[0]);
  }
}