This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics.

 
Nabila Mohammad
Ranch Hand
Posts: 661
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


When I am changing the argument of addAnimal() from addAnimal(ArrayList<Animal> animals) to addAnimal(List<Animal> animals)
Why is the code compiling and running with out errors?

I know, in the first case its the actual object and in the second case its a reference type but I cant understand how it's making a difference.
 
sridhar row
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hint: List is a interface, ArrayList is a class that implements List
 
Nabila Mohammad
Ranch Hand
Posts: 661
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already know that...
How does it make a differnece....
Please be more clear..I am having a hard time figuring this topic...
 
sridhar row
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are passing a List reference to an ArrayList. It wont work List IS-NOT-A ArrayList the other way is true. Hope the below code helps

 
Nabila Mohammad
Ranch Hand
Posts: 661
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That makes a lot of sense...!

Thanks alot..
 
sridhar row
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are welcome!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic