mazzoty Laurence wrote:I have this tiny little piece of code .
public class Test
{
Test test = new Test();
String x="a";
public Test()
{
x = "b";
}
public static void main(String[] args)
{
System.out.println(new Test().x);
}
}
I really don't get it why this throws StackOverflowException.
Basically, in the main() method, it instantiates a Test object. During this process, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated. This variable is for a Test object, which is assigned to the test variable. During the instantiation of that Test object, there is an instance variable which gets instantiated..... etc. etc. etc........ Stack overflow.
Henry