What is the difference between public <T extends Animal> void addAll (List <T> animals) and public void addAll (List <Animal> animals)?
2 answers
The difference is what types of parameters Listwill be accepted by the method.
In the first method, there Tcan be Animaleither any subclass, therefore it addAllwill accept List<Animal>, a List<Dog>or List<Cat>. Note that this signature is equivalent
public void addAll(List<? extends Animal> animals)
when you don’t need the exact type Animalin the body of the method.
, Animal. Java- , Animal . List<Animal>, List<Dog> List<Cat>.
+10