J2EE DAO类问题 5
视频中看的代码,弄到我的机子上报错,而且我不太清楚这是什么意思。求解释!publicclassDAO<T>{privateQueryRunnerqueryRunner=n...
视频中看的代码,弄到我的机子上报错,而且我不太清楚这是什么意思。求解释!
public class DAO<T> {
private QueryRunner queryRunner = new QueryRunner();
private Class<T> clazz;
public DAO() {
Type superClass = getClass().getGenericSuperclass();
if(superClass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)superClass;
Type[] typeArgs = (Type[]) parameterizedType.getActualTypeArguments();
if(typeArgs != null && typeArgs.length > 0) {
if(typeArgs[0] instanceof Class) {
clazz = (Class<T>) typeArgs[0];
}
}
}
}
} 展开
public class DAO<T> {
private QueryRunner queryRunner = new QueryRunner();
private Class<T> clazz;
public DAO() {
Type superClass = getClass().getGenericSuperclass();
if(superClass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType)superClass;
Type[] typeArgs = (Type[]) parameterizedType.getActualTypeArguments();
if(typeArgs != null && typeArgs.length > 0) {
if(typeArgs[0] instanceof Class) {
clazz = (Class<T>) typeArgs[0];
}
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询