I just saw this weird piece of code in another question. I though it should result in a StackOverflow exception, but it actually does not.
public class Node {
public static Node NIL = new Node(Node.NIL, Node.NIL);
public Node(Object one, Object two) {
// Assign values to fields
}
}
I do think like it is going to explode, because Node.NIL is referencing itself to build.
Can someone explain me why it does not?
staticbut i am not sure – XtremeBaumer 2 hours agoNILfield is constructed as it it was declared asnew Node(null, null), because when the constructor is called,Node.NILhasn't been set to anything yet. – khelwood 1 hour ago