您的位置:首页 > 其它

获取接口的泛型类型

2015-11-09 16:19 411 查看
/** 获取接口的泛型类型 */
public static Class<?> getParameterizedType(Class<?> clazz) {
try {
Type[] a = clazz.getGenericInterfaces();
if (a != null && a.length > 0) {
for (Type type : a) {
if (type instanceof ParameterizedType) {
ParameterizedType type1 = (ParameterizedType) type;
Class<?> cal = (Class<?>) type1
.getActualTypeArguments()[0];
if (BaseRespEntity.class.isAssignableFrom(cal)) {
return cal;
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: