拖拽基本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)
您无法调用基本类型的方法.
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)
它包装value的int价值在哪里.
这是否意味着如果int n = 10那么它的HashCode也将是10?
在int没有一个哈希码.Integer然而,它的包装将具有它包装的价值int.
| 归档时间: |
|
| 查看次数: |
7424 次 |
| 最近记录: |