Java: Iterator is supposed to always return the same object, but should change it between calls of next()
问题 The Iterator I'm writing is supposed to iterate through all fixed-sized connected subgraphs of another given graph. As these subgraphs are all very similar (only minor changes in a search-tree based algorithm), I don't want to create a new object to return on each call of next() because of runtime concerns. Therefore I have an object subGraph that is returned every time, but is changed by a function update() between calls of next() , so that the object works like a view of the current state