There is some ambiguity coming here when testing in j2sdk1.4.1_01 .
This is from chapter 5 in Kathy and Bert's book. Below is the code given.
Case 1:
class A{
A(){this("foo");}
A(String s){A() ;)
}
Case 2:
public void go(){
doStuff();
}
public void doStuff(){
go();
}
The book says that it depends upon compiler. The compiler may not catch this problem and running them will give a stack overflow in both the cases.
When I try them seperately in j2sdjk1.4.1_01
case 1 gives me compiler error for recursive constructor invocation.
But case 2 compiles fine and gives stack overflow as indicated in the book.
It looks to me that the same compiler behaving differently for constructor and normal method . Which is surprising ! I could not find anything about this in the JLS also. Hope this kind of question will not be there in the exam.
May be somebody can throw some light on it.
Thank you,
Ambapali
[ January 27, 2003: Message edited by: Thomas Paul ]
This is from chapter 5 in Kathy and Bert's book. Below is the code given.
Case 1:
class A{
A(){this("foo");}
A(String s){A() ;)
}
Case 2:
public void go(){
doStuff();
}
public void doStuff(){
go();
}
The book says that it depends upon compiler. The compiler may not catch this problem and running them will give a stack overflow in both the cases.
When I try them seperately in j2sdjk1.4.1_01
case 1 gives me compiler error for recursive constructor invocation.
But case 2 compiles fine and gives stack overflow as indicated in the book.
It looks to me that the same compiler behaving differently for constructor and normal method . Which is surprising ! I could not find anything about this in the JLS also. Hope this kind of question will not be there in the exam.
May be somebody can throw some light on it.
Thank you,
Ambapali
[ January 27, 2003: Message edited by: Thomas Paul ]