aspose file tools*
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "What does it mean ?" Watch "What does it mean ?" New topic
Author

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 ?

Thanks


"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 ]
 
Consider Paul's rocket mass heater.
 
subject: What does it mean ?