Why there are different hashCode values for each time you run a java main?
Look the example code below.
interface testInt{
public int getValue();
}
enum test implements testInt{
A( 1 ),
B( 2 );
private int value;
private test( int value ) {
this.value = value;
}
public int getValue() {
return this.value;
}
}
For each time you run,
public static void main( String[] args ) {
System.out.println( test.A.hashCode() );
}
there will be different printed values on the console.
Why that inconsistency?
If you want the same value each time, use
.ordinal()or even better, usegetValue()like you have. You can override hashCode() from the default which is to give it a number which is based on the way the object was created.