please see the following code:
import java.util.ArrayList;
public class Animal{...}
public class Dog{...}
public class TestAnimal{
public static void killAll(ArrayList <T extends Animal> animals){
System.out.println("animals are dead");
}
public static void main(String[] args){
ArrayList<Animal> simonAnimal = new ArrayList<>();
ArrayList<Dog> simonDog = new ArrayList<>();
killAll(simonAnimal);
killAll(simonDog);
}
}
the line that causes the problem is:
public static void killAll(ArrayList <T extends Animal> animals){
so what I want to do is to be able to use killAll() method on the any ArrayList that contains objects that are the sub class of Animal, in this case - the Dog class. I don't know what's wrong with my code. please help!
the error message is: Incorrect number of arguments for type ArrayList; it cannot be parameterized with arguments <T, Animal>
I just replaced
<T extends Animal>
as
<? extends Animal>
it works, but can someone tell me why doesn't work?