現在、大きな脳のおならがあります。
私はこれを持っています:
public static final Map<WorkType, Class> handler;
それで
handler = new TreeMap<WorkType, Class>() {{
put(WorkType.SUBMIT, UtilityHandler.class);
}};
それで
JobHandler jobHandler = instantiateHandler(handler.get(work), work, buildingId);
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// !!!!!!!!!!!!!!!!! this shows a warning unchecked assignment
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// Unchecked assignment: 'java.lang.Class' to 'java.lang.Class<? extends JobHandler>
それで
@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;
しかし、それは許可されていません。考えや提案はありますか?ありがとう。