aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes ArrayList and List Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "ArrayList and List" Watch "ArrayList and List" New topic
Author

ArrayList and List

Heba Mahmoud
Ranch Hand

Joined: Apr 26, 2009
Posts: 62


why when passing to the method List<Animal> instead of ArrayList<Animal> it cause a complair error
The method checkAnimals(ArrayList<Animal>) in the type AnimalDoctorGeneric is not applicable for the arguments (List<Animal>)
although we can say List<Animal> a= new ArrayList<Animal>(); when declaring it.

SCJP Pass 85%....
Thousands of candles can be lighted from a single candle, and the life of the candle will not be shortened
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19066
    
  40

why when passing to the method List<Animal> instead of ArrayList<Animal> it cause a complair error
The method checkAnimals(ArrayList<Animal>) in the type AnimalDoctorGeneric is not applicable for the arguments (List<Animal>)
although we can say List<Animal> a= new ArrayList<Animal>(); when declaring it.


Because while all ArrayList<Animal> IS-A List<Animal> is true, which is why the assignment is legal, not all List<Animal> IS-A ArrayList<Animal>, which is why the method call is not legal.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: ArrayList and List