It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Two Empty Generic Class Comparison Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Two Empty Generic Class Comparison" Watch "Two Empty Generic Class Comparison" New topic

Two Empty Generic Class Comparison

Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952
All instances of the generic class have the same runtime class, regardess of actual type parameters.
for instance:

Vector<String> vector=new Vector<String>();
Vector<Integer> vector1=new Vector<Integer>();
it will return true.

Empty vector classes are meaningfully equal.

it will return true.

if vectors are not empty ...
then it will return false.

ArrayList and Vector are the type of List. If two List are empty then they are equal.

ArrayList<Integer> arrayList=new ArrayList<Integer>();
Vector<String> vector=new Vector<String>();
it will return true.

but the concrete class of ArrayList and Vector not same. so..
it will return false.

The same concept will apply to Set classes and Map classes. Remember if generic classe objects are empty then only they are equal.

[ December 08, 2008: Message edited by: Punit Singh ]
[ December 08, 2008: Message edited by: Punit Singh ]

I agree. Here's the link:
subject: Two Empty Generic Class Comparison
jQuery in Action, 3rd edition