/**
* 从范型接口中获取范型对象
* 1. 先获取被代理类IService接口的范型列表,预期结果[interface org.jeecg.modules.*.service.*Service]
* 2. 从第一步获取到到*Service范型接口中获取范型列表,预期结果[com.baomidou.mybatisplus.core.mapper.BaseMapper<org.jeecg.modules.*.entity.*>]
* 3. 从获取到到范型列表中获取使用到实体类class, 预期结果[class org.jeecg.modules.*.entity.*]
*
* @param interfaceClass
* @return Class<?>
*/
private Class<?> getClassFromInterface(Class<?> interfaceClass) {
Type[] types = interfaceClass.getGenericInterfaces();
if (types.length == 0) {
return interfaceClass;
}
Type classType = types[0];
if (classType instanceof ParameterizedType) {
types = ((ParameterizedType) classType).getActualTypeArguments();
if (types.length == 0) {
return interfaceClass;
}
return (Class<?>) types[0];
}
return getClassFromInterface((Class<?>) classType);
}
从范型接口中获取范型对象
最新推荐文章于 2022-07-20 00:13:33 发布