【发布时间】:2018-06-08 19:15:57
【问题描述】:
public class Employee {
int id;
String value;
@Override
public boolean equals(Object obj) {
return true; }
@Override
public int hashCode() {
System.out.println("hi this is my hashcode " + this.hashCode());
return this.hashCode();}
}
public class TestCH {
public static void main(String args[])
{
Employee emp1= new Employee();
Employee emp2= new Employee();
Employee emp3= new Employee();
Employee emp4= new Employee();
Map map= new HashMap();
map.put( emp1,1);
map.put(emp2,2);
map.put(emp3,3);
System.out.println("with map "+map.size());
}
}
在这段代码中,我试图通过 System.out.println 打印哈希码正在生成 StackOverflowError。为什么我收到 StackOverflowError 谢谢你
【问题讨论】:
-
这里是something 以深入了解递归。
-
你设置断点调试程序1分钟怎么样?或者简单地看一下 StackOverflowError 的堆栈跟踪。
标签: java