您的位置:首页 > 其它

list泛型类型获取

2015-10-23 00:00 274 查看
Field field = TestList.class.getDeclaredField("list"); //myList的类型是List

Type type = field.getGenericType();

if (type instanceof ParameterizedType) {

ParameterizedType paramType = (ParameterizedType) type;

Type[] actualTypes = paramType.getActualTypeArguments();

for (Type aType : actualTypes) {

if (aType instanceof Class) {

Class clz = (Class) aType;

System.out.println(clz.getName()); //输出java.lang.String

}

}

}

版权声明:本文为博主原创文章,未经博主允许不得转载。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: