• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StackOverflowError error at Runtime :(

 
Amit Das
Ranch Hand
Posts: 206
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm getting a StackOverflowError at runtime....plz guide me why....


/*since 'an' is an instance reference variable for class Anonymous, i've created an instance of class Anonymous, in the main(), which accesses the instance variable 'an' and since it refers an object of the anonymous class instance, i call the method call() by using it.*/

plz help me out,,
 
Mihai Alexe
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with your code is that the Anonymous default constructor gets called somewhat "recursively". When you are calling the Anonymous constructor inside main() (i.e. new Anonymous()), the component objects get initialized first. That is, the constructor gets called again, because the an objects [of type Anonymous as well] needs to be assigned its value before the constructor finishes. There you go - an infinite constructor call chain - eventually ending in a StackOverflowException. I used the IBM JDK as well, and it refused to load my class - perhaps this compiler is a little "smarter" than the SUN javac
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic