【发布时间】:2012-02-24 18:18:12
【问题描述】:
为什么每次运行 java main 都有不同的 hashCode 值? 请看下面的示例代码。
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;
}
}
每次跑步,
public static void main( String[] args ) {
System.out.println( test.A.hashCode() );
}
控制台上会有不同的打印值。 为什么会出现这种不一致?
【问题讨论】:
标签: java interface enums hashcode