title: Implementing Iterable with a nested class in Java
body: <p>Here is my code:</p>
  
  <pre><code>import java.util.List;
  
  public class ItemList implements Iterable&lt;Entry&gt; {
      private List&lt;Entry&gt; entries;
  
      public static class Entry {
          private final String id;
          private int quantity;
      }
  
      @Overide public Iterator&lt;Entry&gt; iterator() {
          return entries.iterator();
      }
  }
  </code></pre>
  
  <p>This code will not compile.  (It claims it cannot find the "Entry" type in the ItemList class definition).</p>
  
  <p>I want other classes to be able to iterate over the internal entries of this List.  I would rather not move the Entry class to a separate file, as that would require exposing many of the inner workings of that class to all of the other classes in the package.</p>
  
  <p>My question is then: Why won't this compile?  And, what is the best way around this problem?</p>