Ok given we can do this
What use could you get from the following generic code
You can't afterall then say
You can only do the following
So yeah I'm curious, there's nothing wrong with the syntax of this example, it just doesn't seem to have any use?
Code:
import java.util.*;
class Animal {}
class Dog extends Animal {}
public class Generics {
public static void main(String... args) {
List<Animal> animalList = new ArrayList<Animal>();
animalList.add(new Dog());
animalList.add(new Dog());
addAnimals(animalList);
}
public static void addAnimals(List<? super Dog> list) {
list.add(new Dog());
}
}
What use could you get from the following generic code
Code:
List<? super Dog> animalList = new ArrayList<Animal>();
You can't afterall then say
Code:
animalList.add(new Animal());
You can only do the following
Code:
animalList.add(new Dog());
So yeah I'm curious, there's nothing wrong with the syntax of this example, it just doesn't seem to have any use?