Implementing Iterable in Java

Posted by Artium on Stack Overflow See other posts from Stack Overflow or by Artium
Published on 2010-04-25T17:25:12Z Indexed on 2010/04/25 17:33 UTC
Read the original article Hit count: 261

Filed under:
|

I have the following code

public class A extends Iterable<Integer> {
    ...
    public Iterator<Integer> iterator() {
        return new Iterator<Integer>() {

            A a;

            public boolean hasNext() {
                ...
            }

            public Integer next() {
                ...
            }

            public void remove(){
                ...
            } 
};

I would like to initialize the "a" field in the anonymous class with the instance of A that iterator method was called on. Is it possible?

Thank you.

© Stack Overflow or respective owner

Related posts about java

Related posts about iterator