First of all, "List<? super Dog>" in a function argument list means: This function can accept any list whose generic type is a Dog or higher than Dog or even Object. And, we can ADD a Dog or anything below Dog to "animalList".
And, in the for-each loop, the left hand side of the : is a reference type that points to what type of element is returned by the collection on the right hand side. So, our right hand side, i.e. animalList, can accept Dog or higher than Dog. In accordance with that, your left hand side should be big enough to accept Dog or higher than Dog, which can even be an Object.
If you give for(List<Animal> d : animalList), it can accept only Animal. So, the right thing should be for(Object d : animalList), which can hold anything of the 'animalList' collection(Which can be a Dog, Animal or Object).
Mukki, As I said earlier, the enhanced for loop syntax should be noted. K&B says this...
declaration: The newly declared block variable, of a type compatible with the elements of the array you are accessing. This variable will be available within the for block, and its value will be the same as the current array element.
So, in for (ElementType variable : Some_collection), the "ElementType" is the type of EACH element in "Some_collection". So, in your said example, we need to put Object in place of "ElementType" so that it can accept anything of the 'animalList' collection.
Hope I am clear. [ October 20, 2008: Message edited by: Rekha Srinath ]