I am trying to iterate through a recursive object but Java has no support for this from what I know.
For example, given the object Item
:
pub
If you don't have cycles within the parent-child tree you can use a simple recursive function to determine the number of descendants:
public class Item {
...
public int getDescendantCount() {
int count = 0;
if (children != null) {
count += children.size();
for (Item child : children)
count += child.getDescendantCount();
}
return count;
}
}