public class DAOHelper {
private static final Map<Class, Class> DTO_TO_DAO_MAP;
private static final Map<Class, Class> ACDTO_TO_ACDAO_MAP;
static {
DTO_TO_DAO_MAP = new HashMap<Class, Class>();
DTO_TO_DAO_MAP.put(EmployerDTO.class, EmployerDAO.class);
ACDTO_TO_ACDAO_MAP = new HashMap<Class, Class>();
ACDTO_TO_ACDAO_MAP.put(AcademicDTO.class, AcademicDAO.class);
}
public static BaseDAO<?> getDAO(Class dtoClass) {
BaseDAO<?> dao = null;
Class daoClass = ACDTO_TO_ACDAO_MAP.get(dtoClass); //here
//rest of code here
}
Class daoClass = ACDTO_TO_ACDAO_MAP.get(dtoClass);
在这部分代码中,而不是ACDTO_TO_ACDAO_MAP
如何让代码自动检测到这一点,所以我不会为每个可能的代码DTO_TO_DAO_MAP
或其他代码手动执行它......