Douglas Harder
2005-01-15 07:31:50 UTC
Hello,
Someone after class claimed that he could use Object's default hashCode()
method without overriding it and still satisfy the conditions required by
the project specifications. I have tried, again and again, to recreate the
behaviour where multiple objects with identical instance variables created
the same hash using Object's default hashCode method. Would this individual
please supply me with the source code which produced this interesting
result? In the following piece of code, you will note that each object,
although having equal instance variables, returns different hash values.
public class Temp {
private int x;
public Temp( int i ) {
x = i;
}
public static void main( String[] args ) {
Temp[] a = new Temp[1000];
for ( int i = 0; i < a.length; i++ ) {
a[i] = new Temp( 0 );
System.out.println( a[i].hashCode() );
}
for ( int i = 0; i < 1000; i++ ) {
Temp x = new Temp( 0 );
System.out.println( x.hashCode() );
}
}
}
If you can give me something which is reproducable, I would be very
interested.
Thank you,
Douglas
Someone after class claimed that he could use Object's default hashCode()
method without overriding it and still satisfy the conditions required by
the project specifications. I have tried, again and again, to recreate the
behaviour where multiple objects with identical instance variables created
the same hash using Object's default hashCode method. Would this individual
please supply me with the source code which produced this interesting
result? In the following piece of code, you will note that each object,
although having equal instance variables, returns different hash values.
public class Temp {
private int x;
public Temp( int i ) {
x = i;
}
public static void main( String[] args ) {
Temp[] a = new Temp[1000];
for ( int i = 0; i < a.length; i++ ) {
a[i] = new Temp( 0 );
System.out.println( a[i].hashCode() );
}
for ( int i = 0; i < 1000; i++ ) {
Temp x = new Temp( 0 );
System.out.println( x.hashCode() );
}
}
}
If you can give me something which is reproducable, I would be very
interested.
Thank you,
Douglas