实例化中绑定的Java泛型参数
现在有一个大脑大放屁 我有这个:实例化中绑定的Java泛型参数,java,generics,Java,Generics,现在有一个大脑大放屁 我有这个: public static final Map<WorkType, Class> handler; 公共静态最终映射处理程序; 然后 handler=newtreemap(){{ put(WorkType.SUBMIT,UtilityHandler.class); }}; 然后 JobHandler-JobHandler=instanceHandler(handler.get(work)、work、buildingId); // !!!!!!!
public static final Map<WorkType, Class> handler;
公共静态最终映射处理程序;
然后
handler=newtreemap(){{
put(WorkType.SUBMIT,UtilityHandler.class);
}};
然后
JobHandler-JobHandler=instanceHandler(handler.get(work)、work、buildingId);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!! 这将显示一个未选中的分配警告
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//未经检查的赋值:“java.lang.Class”到“java.lang.Class我认为您应该声明
Map<WorkType, Class<? extends JobHandler>> handler
Map我想你想要:
Map<WorkType, Class<? extends JobHandler>> handler
MapWell,那太尴尬了。谢谢我把它放在下面,不知道为什么我认为它在上面不起作用。
@SuppressWarnings(value="unchecked")
private static JobHandler instantiateHandler(Class<? extends JobHandler> ref, WorkType type, String id) {
if(ref == null) {
throw new UnsupportedOperationException("This action is not supposed!");
}
try {
Constructor<JobHandler> constructor = (Constructor<JobHandler>) ref.getConstructor(WorkType.class, String.class);
JobHandler handler = constructor.newInstance(type, id);
return handler;
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException e) {
Utilities.writeLogException(null, e);
}
return null;
}
public static final Map<WorkType, Class extends JobHandler> handler;
Map<WorkType, Class<? extends JobHandler>> handler
Map<WorkType, Class<? extends JobHandler>> handler