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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 18101
    
  39

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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ArrayList and List
 
Similar Threads
Super bounded WildCards -Doubt
Clarification about ? super Object
Wildcards in Generics
Chapter 7 - Objective 6.3 & 6.4 - type parameter for method checkAnimals () method.
Generics problem- why not taking Animal, Object and super of Dog