This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help in generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help in generics" Watch "Help in generics" New topic
Author

Help in generics

jose chiramal
Ranch Hand

Joined: Feb 12, 2010
Posts: 266
Hi, Could someone please help me understand the below concept :

"An ArrayList<Animal> can accept references of type Dog, Cat, or any other subtype of Animal (subclass, or if Animal is an interface, implementation)."


Additionally could someone please point me to understand any good link for understanding the concepts used in Generics.
Devaka Cooray
ExamLab Creator
Saloon Keeper

Joined: Jul 29, 2008
Posts: 3013
    
  35

In simple terms, if there is a reference like "ArrayList<Animal> anim", you can add a dog, cat, cow, or any other animal into that object, using the add(-) method. You may have a look at the Sun Generics tutorial.


Founder of ExamLab and Systemup
See how I can help you to become an awesome programmer
Prithvi Sehgal
Ranch Hand

Joined: Oct 13, 2009
Posts: 774
Hello jose,

Check JavaGenericsFaq

Hope this helps,


Prithvi,
My Blog, Follow me on Twitter,Scjp Tips, When you score low in mocks, Generics,Scjp Notes, JavaStudyGroup
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help in generics
 
Similar Threads
wildcards in generics
Generics doubt ?
Generics + Polymorphism
Generics
generics