有没有办法看到原始类型的HashCode?

Noo*_*tor 5 java hashcode

拖拽基本DS ...我读过,没有hashCode()基本类型的int方法可用,如果被调用int,它将抛出错误

错误:int无法解除引用

这是否意味着如果int n = 10那么它HashCode也将是10?

如果我仍然需要int在下面的程序中看到hascode ,有没有办法看到它,如Integer Wrapper???

public static void main(String []args){
       String me = "hello";
       int n = 10;

       int h1 = me.hashCode();
       int h2 = n.hashCode();

       System.out.println(h1);
       System.out.println(h2);
     }
Run Code Online (Sandbox Code Playgroud)

Sot*_*lis 8

您无法调用基本类型的方法.

n被宣布为int.它没有方法.

想想就没有意义

如果我仍然需要在下面的程序中看到int的hascode

你可以创建一个Integer对象并获得它hashCode()

Integer.valueOf(n).hashCode()
Run Code Online (Sandbox Code Playgroud)

Integer#hashCode() 实现为

public int hashCode() {
    return value;
}
Run Code Online (Sandbox Code Playgroud)

它包装valueint价值在哪里.

这是否意味着如果int n = 10那么它的HashCode也将是10?

int没有一个哈希码.Integer然而,它的包装将具有它包装的价值int.