I've this problem:
Given the iterable
class Foo, which keeps always only oneintvalue which is set on its constructor, make an iterator so it respects all of its restrictions which are: you can't change theintvalue after its initialization. You should include only the required exceptions to be thrown.
Ok, so far, if I understood the question the right way, I should create an iterator for that Foo class, however I've never done this before and it seems to be that the question itself is a bit misleading. Is it a list? Or shouldn't it be? Anyway, despite that, all I want to know is how to create it.
So now I've this:
public class Foo implements Iterable<Foo> {
@Override
public Iterator<Foo> iterator() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
But I don't even know if this is the right way to do so. I'd be very appreciated if someone could help me out with this.
Thank you in advance.
iterator()method should beIterator<Something>. Should it beIterator<Foo>orIterator<Integer>or something else?Fooinstance? Nothing?