yet-another-tree-structure
yet-another-tree-structure copied to clipboard
Initial call to next() before calling hasNext() returns null
Just starting to look at this very nice implementation, so apologies if I'm missing something. But it appears that one must always call hasNext() before the first call to next() or a null result will be returned. I don't know if there's any way around this, but the spec for Iterator doesn't impose this requirement.
Upon further analysis, it looks like calls to next() will always return the same value unless hasNext() is called first. I don't think this is how Iterator is supposed to work.
That's a flaw. Calling next() is expected to work without prior call to hasNext(), provided that there are still items to iterate on.