This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Generics" Watch "Generics" New topic


kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
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

Joined: Feb 28, 2007
Posts: 1707
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?


kathir vel
Ranch Hand

Joined: Jul 03, 2007
Posts: 92
Sorry all!!.
I was using AnimalDoctorGeneric1 instead of AnimalDoctorGeneric2 .It was working fine.
Abdullah Mamun
Ranch Hand

Joined: Mar 19, 2007
Posts: 99

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 ]

Don't get me started about those stupid light bulbs.
subject: Generics
Similar Threads
Help me fix this-Part-2,so I can compile(generics doubt)
Collections and me...
Doubt in K&B SCJP 5: topic Generics
Chapter 7 - Objective 6.3 & 6.4 - type parameter for method checkAnimals () method.
Help me fix this,so I can compile(generics doubt)