Hier ist mein Code:Java Generika - ein generisches zum anderen Casting
public class AnimationManager<STATE> {
private Map<STATE, Animation> animationMap = new HashMap<STATE, Animation>();
public void addAnimation(STATE state, BufferedImage[] frames, int frameDuration){
animationMap.put(state, new Animation(frames, frameDuration));
}
public <E extends Enum<E>> void initAnimations(Player player, Constants.Heros chosen_hero, Class<E> heroStates){
LinkedList<BufferedImage[]> frames = AssetsManager.getHeroGraphics(chosen_hero);
assert frames != null;
player.width = frames.get(0)[0].getWidth();
player.height = frames.get(0)[0].getHeight();
for(int i=0;i<frames.size();i++)
addAnimation(heroStates.getEnumConstants()[i],frames.get(0),15);
}
}
An dieser Linie:
addAnimation(heroStates.getEnumConstants()[i],frames.get(0),15);
Compiler ruft: Wrong 1. Argument Typ, gefunden 'E', erforderlich ‚STATE ".
Wenn initAnimations()
Methode ist in einer anderen Klasse (ohne STATE) kompiliert und funktioniert wie ein Charme. Wie ist das möglich, dass er den ersten Parameter nicht erhalten und in einen STATE-Typ umwandeln will?
Aw, das ist jetzt klar. Vielen Dank! –