look at the first paragraph of code
public class Test {
public Test test = new Test();
public void say() {
System.out.println("hello world!");
}
public static void main(String[] args) {
new Test();
}
}
the above code will cause a dead loop and lead to a memory overflow. Let"s take a look at the second code
public class Test {
public static Test test = new Test();
public void say() {
System.out.println("hello world!");
}
public static void main(String[] args) {
//
new Test().test.test.test.test.test.say();
}
}
in the second section of code above, new Test (). Test.say ();
can be referenced indefinitely, but is there an endless loop? why? Can someone analyze the second kind of code from a memory point of view?