• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ArrayList and List

 
Heba Mahmoud
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
Henry Wong
author
Marshal
Pie
Posts: 21420
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic