• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

ArrayList and List

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic