I have a method that takes a list of a super class (Specifically my class Mob). It looks like this:
List<? extends Mob> mobs
I want to be able to add any object which extends the super class Mob to this list, like this:
spawnMob(new Zombie(World.getInstance(), 0, 0), World.getInstance().getZombies());
Where this is the method in question:
public static void spawnMob(Mob mob, List<? extends Mob> mobs){
mobs.add(mob);
}
This line of code World.getInstance().getZombies() returns a List of the object Zombie. Zombie extends Mob.
However, this line of code:
mobs.add(mob);
Throws this error:
The method add(capture#1-of ? extends Mob) in the type List<capture#1-of ? extends Mob> is not applicable for the arguments (Mob)
What can I do to resolve this?
Edit, after changing the method to except List<Mob> I receive this error:
The method spawnMob(Mob, List<Mob>) in the type MobSpawner is not applicable for the arguments (Zombie, List<Zombie>)
List<Mob> mobs? You can still add objects extending Mob to that list.