• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does it mean ?

 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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>
 
Edisandro Bessa
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
*Bump*. Now I see. Now it's clear.

Thank you Sir.
[ April 18, 2006: Message edited by: Edisandro Bessa ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic