• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StackOverflowError

 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

is same as


so, every recursive call a stack object created by jvm endlessly, hence that error.
 
Matthew Brown
Bartender
Posts: 4567
8
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or to put it another way: every time you create a Test1, that creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1, which creates a new Test1...
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:which creates a new Test1...

Yes, at last no instances are created *fully*/consistenly
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Seetharaman and Matthew. So, in this case #2 will cause a Test1 class to load and while loading it will create another class instance at #1 and while loading that instance it will load another class instance at #1 and so on... Is this where the recursion happening?
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when you say java x.y.z.ClasstoRun then Jvm load that class and search for a main method...and then creating instance etc.. got the difference?
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, in this case, when jvm load the class what line will be executed first #1 or #2 (from main method)?
 
William P O'Sullivan
Ranch Hand
Posts: 859
Chrome IBM DB2 Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
#2
then
#1
#1
#1

...

ad infinitum (well, until Stack overflows)

WP
 
Janki Shah
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood the point. Thank you William.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic