File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Recursive Methods

 
Henrique Ordine
Ranch Hand
Posts: 128
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello everyone,
I wrote this dummy tree class which is associated to itself, and i populate it using a recursive method. The recursive method, getMyChildren, is used to add child objects to parent object, and then grandchildren to children, and so on.
In my method, after the recursion, I test the collection of children and they're always empty, even though they're not.
Does anyone know why this happens? I would appreciate any thoughts.

Here is my code:

 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm having an extremely hard time following the logic here, or why a method called "getMyChildren" would be the way to build a a tree in the first place. But in any case, there's only one place in the whole program where you call children.add():



So if there are already some children, add a new child. But of course, since we start out with no children, that's never going to change.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic