As far as I understand, the following code should print HashCodecollections, since I print it HashCodedirectly.
However, when I run the following code, I get an error Stack overflow:
public class Test1 {
public static void main(final String[] args) {
m1(new LinkedHashSet<Collection<?>>());
}
private static void m1(final Collection<Collection<?>> cl) {
cl.add(cl);
try {
System.out.println(cl.hashCode());
} catch (Error err) {
System.out.println(err);
}
}
}
Can someone explain this behavior?
source
share