SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
SCJP 5.0 , SCEA Java EE 5, TOGAF Certified
Sunderam Goplalan wrote:By this you are telling the client that, "I will allow you to add anything that's above the "Dog" in the hierarchy. Not anything below such as a Cat, as this may pollute your collection.
It would be really strange if you would have a class Cat that extends class Dog. If you do that, you're saying that a Cat is a special kind of Dog. My cat will certainly disagree with that... So, the second half of your example is a little strange
SCJP 5.0 , SCEA Java EE 5, TOGAF Certified
Rico Felix wrote:Don’t use a wildcard when you want to both get values out and put values into a structure
Tess Jacobs wrote:
Rico Felix wrote:Don’t use a wildcard when you want to both get values out and put values into a structure
Is this statement accurate? The following processAnimals(List<? super Animal> animals) method allows me to get values out and put values in. Maybe it's just not advisable to get values out as Objects due to the possibility of ClassCastException. Similarly, it's not advisable to add null into List<? extends Animal> animals due to the possibility of NullPointerException.