![]() Main page FAQ HOWTO Components Page Index myWMS News ![]() Mailinglist ![]() lexicon ![]() Recent Changes WikiEtiquette Find pages Unused pages Undefined pages Impressum ![]()
Set your name in
UserPreferences Referenced by
JSPWiki v2.2.33
i18n support |
Please assume the following code:
public static void main(String[] args) {
Long a,b;
long i,j,n;
n = 100000L;
for(i=0;i<n;i++) {
a = new Long(i);
for(j=0;j<n;j++) {
if(i==j) {
continue;
}
b = new Long(j);
if(a.hashCode() == b.hashCode()) {
System.out.println("a="+i+"; b="+j);
}
}
}
}
On my machine this code does not deliver two equal hashes for different values. But who knows what would happen with 100001? In fact type long does contain much more values than int and the method hashCode() does return long values. myWMS does make use of its own implementation of hashCode() (getHashKey()) to identify BusinessObjects and their BusinessObjectIdentifiers. BusinessObjects and BusinessObjectIdentifiers are stored in Hashtables several times, using the getHashKey() method to specify the key of the key/value pair. Internally the Hashtable not only checks the value returned by hashCode(), it also compares the specified key using the equals() method (please refer to the source of class java.util.Hashtable, beginning in line 383 in @version 1.90, 12/13/01). Using the method equals() helps us to keep appart possibly different values with equal hash codes. However, the use of getHashKey and hashCode() in myWMS seems to be secure for now. See: Long.hashCode()
|
||||||