Hello, there is a task
private class IteratorImpl implements Iterator<Object> { public boolean hasNext() { //returns true if the iteration has more elements // ... } public Object next() { // returns the next element in the iteration // ... } public void remove() { //removes from the underlying collection the last element returned by this iterator // ... } } The algorithm in the remove method may be as follows:
IF BEFORE CALLING, REMOVE WAS NOT CALLED METHOD next OR BEFORE CALLING REMOVAL WAS CALLED remove (call again remove) TO CLEAR EXCLUSION (just insert it into the code): throw new IllegalStateException (); IN THIS PLACE, DETERMINE AND REMOVE THE RELEVANT ELEMENT
implemented the first two methods, stayed remove.
Question: I don’t understand how to implement it? How to find out which methods were called before remove, and I don’t understand how to remove either.