工具类:(泛型转化)
【例子】:
超类
public class GenericDAO<T> {
private Class<T> entityClass;
protected GenericDAO() {
Type type = getClass().getGenericSuperclass();
Type trueType = ((ParameterizedType) type).getActualTypeArguments()[0];
this.entityClass = (Class<T>) trueType;
}
}
子类
public class OptionManager extends GenericDAO<MSGC_OPTION> {
}
测试类
public class OracleTest {
public static void main(String[] args) throws Exception {
OptionManager manager = new OptionManager();
}
}
这样在你new OptionManager();以后
超类里的entityClass就是子类那里的public class OptionManager extends GenericDAO<MSGC_OPTION> 里面的MSGC_OPTION所对应的class对象了..