public D newUsr(){
D newUsr;
try {
// 通过反射获取model的真实类型
ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass();
Class<D> clazz = (Class<D>) pt.getActualTypeArguments()[0];
// 通过反射创建model的实例
newUsr = clazz.newInstance();
} catch (Exception e) {
throw new RuntimeException(e);
}
return newUsr;
}
那个数组下标是对应的传进来的第几个泛型。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)