This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help in generics

 
jose chiramal
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 4265
229
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello jose,

Check JavaGenericsFaq

Hope this helps,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic