小编Víc*_*ugo的帖子

不同的Enum HashCode生成?

为什么每次运行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;
    }
}
Run Code Online (Sandbox Code Playgroud)

每次跑步,

public static void main( String[] args ) {
     System.out.println( test.A.hashCode() );
}
Run Code Online (Sandbox Code Playgroud)

控制台上会有不同的打印值.为何不一致?

java enums interface hashcode

7
推荐指数
1
解决办法
1353
查看次数

标签 统计

enums ×1

hashcode ×1

interface ×1

java ×1