File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

regarding generics

 
debasmita pattnayak
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

i am confused about the following stuff:



please explain me this...i am not sure about the lines in which i have put comments
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The list is declared to accept instances of Animal.

Since Cat extends Animal, a Cat IS-AN Animal. Since Dog extends Animal, a Dog IS-AN Animal. So there is no problem adding these to the List.

The thing to consider is that everything you get out of the List will be a reference of type Animal, so if you intend to downcast back to Cat or Dog, you will need to take some precautions (e.g., check the actual type using instanceof before downcasting).
[ July 04, 2007: Message edited by: marc weber ]
 
debasmita pattnayak
Ranch Hand
Posts: 94
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi marc,
thanks for the reply....
its clear now....
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic