A DESCRIPTION OF THE REQUEST :
Enum.hashCode() call System.identityHashCode() that
is seven times slower than Object.hashCode().
Note that I don't know why and perhaps, System.identityHashCode()
may be optimized.
JUSTIFICATION :
it's improve performance
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
public final int hashCode() {
return super.hashCode();
}
ACTUAL -
public final int hashCode() {
return System.identityHashCode(this);
}
---------- BEGIN SOURCE ----------
It's just a micro benchmark than test super.hashCode()
and System.identityHashCode(this)
/**
* @author remi
*
*/
public class MyEnumTest {
static class Zuper {
public final int hashCode() {
return super.hashCode();
}
}
static class Identity {
public final int hashCode() {
return System.identityHashCode(this);
}
}
static long test(Object o) {
long time=System.nanoTime();
for(int i=0;i<1000000;i++)
o.hashCode();
return System.nanoTime()-time;
}
public static void main(String[] args) {
System.out.println("super "+test(new Zuper()));
System.out.println("identity "+test(new Identity()));
}
}
---------- END SOURCE ----------
###@###.### 10/21/04 23:26 GMT