aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Generics. 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 "Generics." Watch "Generics." New topic
Author

Generics.

Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661


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.


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
Hint: List is a interface, ArrayList is a class that implements List
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
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

Joined: Jan 16, 2008
Posts: 162
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

Joined: Nov 05, 2007
Posts: 661
That makes a lot of sense...!

Thanks alot..
sridhar row
Ranch Hand

Joined: Jan 16, 2008
Posts: 162
you are welcome!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics.