I want to add two enemies to the pane, Dragon
and Orc
. Both of these classes extend a super class called Entity
, and I want to create a single method for both these methods. I have tried using List<? extends Sprite> list
and List<? super Sprite> list
, but it didn't work as I need to both add the object to a list and read it later on when calling the add method.
public void addDragon(List<Dragon> list) {
double imageWidth = 0;
for(int i = 0; i < 6; i++) {
Dragon dragon = new Dragon();
imageWidth = dragon.getWidth();
pane.getChildren().add(dragon);
list.add(dragon);
}
}
public void addDragon(List<Orc> list) {
double imageWidth = 0;
for(int i = 0; i < 6; i++) {
Orc orc = new Orc();
imageWidth = orc.getWidth();
pane.getChildren().add(orc);
list.add(orc);
}
}