• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics

 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
In this following program I couldn't see the execution of Line 1 and Line 2. Anyone please clarify me?Thanks.





code indenting repaired by using the button, Bu
[ July 18, 2007: Message edited by: Burkhard Hassel ]
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathir,

What couldn't you see on line #1 and #2. You are passing a list to the method,
adding Dog, Cat and Bird objects to it accordingly. Inside the method, you are
adding a Dog object to every passed list and after printing its size, you
are traversing the list.
What do you see wrong there?



Thanks,
 
kathir vel
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry all!!.
I was using AnimalDoctorGeneric1 instead of AnimalDoctorGeneric2 .It was working fine.
 
Abdullah Mamun
Ranch Hand
Posts: 99
Eclipse IDE Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kathir,
The source gives compiler error at the following lines

The reason is, there is a down casting from List to ArrayList. So you have to cast explicitly.

[ July 17, 2007: Message edited by: Al Mamun ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic