0
public interface  GenericDAO<T>{
   // some methods
}
public interface PersonGenericDAO extends GenericDAO<Person> {}
public interface TeacherGenericDAO extends GenericDAO<Teacher> {}
public interface StudentGenericDAO extends GenericDAO<Student> {}

我有一个库,它通过这些接口创建代理实例,如下所示:

creator.onDemand(PersonGenericDAO.class);

我只想创建一个静态方法来删除不必要的接口。但我对此一无所知。

public static <X> GenericDAO<X> getGenericDAO(X type){
   // return ?????????? 
}
4

1 回答 1

0

使参数 a Class<X>

public static <X> GenericDAO<X> getGenericDAO(Class<X> type){
   return new HibernateDAO<X>();
}

并将其称为

GenericDao<Person> personDao = getGenericDAO(Person.class);
于 2012-10-21T21:02:55.460 回答