wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes What does it mean ? 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 "What does it mean ?" Watch "What does it mean ?" New topic

What does it mean ?

Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
Hi guys,

What does the following affirmation mean ?

"All instances of a generic class have the same runtime class, regardless of their actual type parameters. So it is not meaningful to use the instanceof operator to check if an object is the instance of a particular invocation of a generic type."

Could you please explain by using code ?


"If someone asks you to do something you don't know how to, don't tell I don't know, tell I can learn instead." - Myself
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
An example: ArrayList<String> list1, ArrayList<List> list2, ArrayList<Integer> list3, ArrayList<Double> list4 are all reduced to the raw type ArrayList at runtime. So you can only ask if list1 instanceof ArrayList, or list2 instanceof ArrayList, and so on. You cannot ask if list1 instanceof ArrayList<String> or list2 instanceof ArrayList<List>

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Edisandro Bessa
Ranch Hand

Joined: Jan 19, 2006
Posts: 584
*Bump*. Now I see. Now it's clear.

Thank you Sir.
[ April 18, 2006: Message edited by: Edisandro Bessa ]
It is sorta covered in the JavaRanch Style Guide.
subject: What does it mean ?
Similar Threads
Inheritance when extending ArrayList of superclass? Help? :[
Generic method question
User Defined Generics Type
Regarding Generic Types
Using "super" in Generics