First, don't take it too hard. I just post it for fun (but it is correct thing except that it can't be consider the useful one). This is the code:
assume that the Animal and its subclass is correct implements.
This code is work fine, which mean it 'fine' both in compile and run time. I can invoking addAnimal( List<Dog> ) , addAnimal( List<Cat> ) as it was in wildcard generics fashion.
The point is, the method that declare wild
cards generic (e.g. List<? extends SuperClass> can't invoking the 'modify' method such as add() of List. But you can add 'null' in this method and this 'null' will distribute to every List that you add to this method.
Best Regards
Tanakorn
[ February 11, 2007: Message edited by: Tanakorn Numrubporn ]