posted 17 years ago
I think that you have a very interesting question... And I don't think that the last two implementations are very useful. Look at the classes Animal, Dog and Cat (extend Animals).
Now I input a List of Animals into the 3rd backwards method, and the return type is List<? extends Animal>. Now, what is my return type? A list of Animals? a list of Dogs? a list of Cats and Dogs? you can't tell, but you also can't put the outputted list in a List<Animal> (because it could be a List<Dog> )! You can only put the list in a List<? extends Animal> or an Object.
The same goes for the 4th backward method (is it a List<Object> or List<Animal>?). I think that it is more useful to use 2 specified generics instead of just one, like this:
With this code you can input a List<Animal> and get a List<Dog>, List<Cat> or List<Beagle> in return (it's probably not perfect but illustrates the use of multiple generics).
[ September 19, 2007: Message edited by: Xander Steinmann ]
[ September 19, 2007: Message edited by: Xander Steinmann ]