title: Java, generics and iterators
body: <p>I'm trying to understand why I'm getting this error:</p>
  
  <p>-- This is the error --</p>
  
  <p><code>File: ...\HashTable.java  [line: 103]
  Error: The return type is incompatible with HashTableInterface&lt;Key,Value&gt;.iterators()
  </code></p>
  
  <p>The interface contains an innerclass:</p>
  
  <p><code>public class Entry&lt;Key, Value&gt;{...}</code></p>
  
  <p>and LinkedList is a similar to the java API yet it contains an iterator innerclass, but when testing out something more simple like:</p>
  
  <p>-- This is working code, at least in drjava's interaction pane -- </p>
  
  <pre><code>LinkedList&lt;String&gt; list = new LinkedList&lt;String&gt;();
  Iterator&lt;String&gt; test = list.iterator();
  </code></pre>
  
  <p>yet I cannot get this method to compile inside of my HashTable class:</p>
  
  <p>-- This is the code I cannot get to work --</p>
  
  <pre><code>public Iterator&lt;Entry&lt;Key, Value&gt;&gt; iterator(){
  LinkedList&lt;Entry&lt;Key, Value&gt;&gt; iter = new LinkedList&lt;Entry&lt;Key, Value&gt;&gt;();
  return iter.iterator();
  }
  </code></pre>
  
  <p>I assume its something simple, it doesn't seem too complicated, but any input would be greatly appreciated.</p>
  
  <p>** You're right sorry about that it was supposed to list.iterator();</p>
  
  <p><strong>Edits</strong></p>
  
  <p>-- Alright here's the interface --</p>
  
  <pre><code>import nhUtilities.containers2.*;
  
  interface HashTableInterface&lt;Key, Value&gt; {
  
      public boolean isEmpty();
  
      public Value get(Key key);
  
      public void add(Key key, Value value);
  
      public void remove(Key key);
  
      public void clear();
  
      public Iterator&lt;Entry&lt;Key, Value&gt;&gt; iterator();
  
      public interface Entry&lt;Key, Value&gt; {
  
          public Key getKey();
  
          public Value getValue();
  
          public void setValue(Value value);
  
      }
  }
  </code></pre>
  
  <p>-- this is the implemented entry which is an innerclass of HashTable where the method that is broken resides--</p>
  
  <pre><code>public class Entry&lt;Key, Value&gt; {
      private Key k;
      private Value v;
  
      public Entry(Key key, Value value) {
          k = key;
          v = value;
      }
  
      /**
       * Returns a key of pair;
       */
  
      public Key getKey() {
          return this.k;
      }
  
      /**
       * Returns value of pair;
       */
  
      public Value getValue() {
          return this.v;
      }
  }
  </code></pre>
  
  <p><strong>Edit+</strong></p>
  
  <p>So i just realized </p>
  
  <p><code>public class LinkedList&lt;Element&gt; extends AbstractList&lt;Element&gt;</code></p>
  
  <p>and </p>
  
  <p><code>public abstract class AbstractList&lt;Element&gt; implements List&lt;Element&gt;</code></p>
  
  <p>and</p>
  
  <p><code>public interface List&lt;Element&gt; extends java.lang.Iterable&lt;Element&gt;</code></p>
  
  <p>yet inside of LinkedList there is</p>
  
  <p><code>private class Iterator extends AbstractIterator&lt;Element&gt; 
      implements nhUtilities.containers2.Iterator&lt;Element&gt;</code></p>
  
  <p>perhaps perhaps that is causing the conflict (because the LinkedList i'm using is not the java API LinkedList)?</p>