I have two methods:
public <T extends Component> void addComponent(BluePrint bluePrint, Class<T> type) throws InstantiationException, IllegalAccessException {
AddComponent addComponent = addComponentMap.get(type);
if (addComponent == null) {
addScriptable(bluePrint, type); <--- fails here
}
}
if addComponentMap.get(type);
returns null, i know implicitely that T is of type Scriptabe and need to call:
private <T extends Scriptable> void addScriptable(BluePrint bluePrint, Class<T> type) throws InstantiationException, IllegalAccessException {
scriptableSystems.add(new ScriptableSystem<T>());
}
The issue is that the upper bound for T in the second method is Scriptable and in the first method its Component, therefore type "could" potentially be any component when addComponent is null.
Can i somehow narrow the constraint to Scritpable when addComponent is null? Or somehow explicitly say that when addComponent is null T will extend Scriptable, before calling addScriptable?
Worth mentioning perhaps is that Scriptable inherits from component.