这可以生成对象的实例吗?
public <?> getDAO ( Class<?>DAO){
//if using this DAO class is permitted or DAO class exists
//we have HashMap map
return map.get(DAO);
}
或者也许是
public <T> T getDAO ( <T extends AGenericDAO> DAO){ // GenericDAO<E,I>
//if using this DAO class is permitted or DAO class exists
//we have HashMap map
return map.get(DAO);
}
答案 0 :(得分:1)
听起来你想要的是:
public <T extends AGenericDAO> T getDAO(final Class<T> daoClass) {
return daoClass.cast(map.get(daoClass));
}
其中map
的类型为java.util.Map<Class<? extends AGenericDAO>, AGenericDAO>
。