title: Is it possible to extend the functionality of an iterator in Java?
body: <p>I was wondering if there is a way to extend the functionality of the iterator interface. Suppose that we have a Class that implements the Iterable interface (in the example above, instead of the overridden functions of the Iterator interface I have added myFunction). </p>
  
  <pre><code>public class MyClass implements Iterable{
  
      @Override
      public Iterator iterator() {
          return new Iterator() {
              @Override
              public boolean hasNext() {
                  throw new UnsupportedOperationException("Not supported yet.");
              }
  
              @Override
              public Tuple next() {
                  throw new UnsupportedOperationException("Not supported yet.");
              }
  
              @Override
              public void remove() {
                  throw new UnsupportedOperationException("Not supported yet.");
              }
              public void myFunction(){
  
              }
          };
      }
  }
  </code></pre>
  
  <p>If I put this code in another function I get compilation error ("cannot find symbol") and I was wondering why this happens.</p>
  
  <pre><code>public void anotherFunction(){
      MyClass a = new MyClass();
      a.iterator().myFunction();
  }
  </code></pre>