获得List<T> T的类型

  1. public class GenericTest   
  2. {   
  3.     public List<String> list = new LinkedList<String>();   
  4.   
  5.     public static void main(String[] args) throws SecurityException, NoSuchFieldException   
  6.     {   
  7.         ParameterizedType pt = (ParameterizedType) GenericTest.class.getField(   
  8.                 "list").getGenericType();   
  9.         System.out.println(pt.getActualTypeArguments().length);   
  10.         System.out.println(pt.getActualTypeArguments()[0]);   
  11.     }   
  12. }  

猜你喜欢

转载自guobin6125.iteye.com/blog/1535775
T
今日推荐