This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Pradeep, Suppose I have a the Dog-Animal-Object hierarchy. Obviously it makes sense to call collectionOfAnimals.containsAll(collectionOfDogs).
However, it also makes sense to call collectionOfDogs.containsAll(collectionOfAnimals). I may not know what is in my collectionOfAnimals. It is entirely possible that it contains only dogs (or is empty) and then the call makes sense.
Another reason is consistency. It must be valid to call collectionOfDogs.containsAll(collectionOfObjects) and collectionOfObjects.containsAll(collectionOfDogs) for the same reasons explained above. collectionOfObjects is equivalent to the pre-java 1.5 Collection. So I can get this functionality by using a Collection without specifying a type because java 1.5 is backward compatible. [ December 30, 2004: Message edited by: Jeanne Boyarsky ]