读书人

取得Listlt;Tgt; T的类型

发布时间: 2012-08-11 20:50:31 作者: rapoo

获得List<T> T的类型

    public?class?GenericTest ??{ ??????public?List<String>?list?=?new?LinkedList<String>(); ????????public?static?void?main(String[]?args)?throws?SecurityException,?NoSuchFieldException ??????{ ??????????ParameterizedType?pt?=?(ParameterizedType)?GenericTest.class.getField( ??????????????????"list").getGenericType(); ??????????System.out.println(pt.getActualTypeArguments().length); ??????????System.out.println(pt.getActualTypeArguments()[0]); ??????} ??}??

读书人网 >软件开发

热点推荐