title: Can't call iterator() method of my object
body: <p>I am learning to use the Iterator Interface, but I'm stuck because Eclipse shows "Cannot resolve to a type" when I call the iterator() method of my LinkedList A with A.iterator() in the code block just below. I searched, but I don't find why this happens, and how I can call A.iterator(). This is the code where I try to call the A.iterator()-method:</p>
  
  <pre><code>import abstractDataTypes.LinkedList.*;
  
  public class LinkedListIteratorTest {
      public static void main(String [] args) {
          LinkedList&lt;Integer&gt; A = new LinkedList&lt;Integer&gt;();
          A.insert(1);
          A.insert(3);
          A.insert(1);
          A.insert(7);
          A.insert(6);
          ListIterator li = new A.iterator();
          for(;li.hasNext();) {
              System.out.println(li.next());
          }
      }
  }
  </code></pre>
  
  <p>And this is the part of the code in my LinkedList-class, where interator() is defined:</p>
  
  <pre><code>import java.util.Iterator;
  
  public class LinkedList&lt;T&gt; implements Iterable&lt;T&gt; {
      ListNode&lt;T&gt; head;
      ListNode&lt;T&gt; tail;
  
      public LinkedList() {
          head = null;
          tail = null;
      }
  
      public Iterator&lt;T&gt; iterator() {
          return new ListIterator&lt;T&gt;(head);
      }
  ...
  </code></pre>
  
  <p>ListIterator() is defined as a class inside the LinkedList-class:</p>
  
  <pre><code>    ...
      class ListIterator&lt;T&gt; implements Iterator&lt;T&gt; {
          ListNode&lt;T&gt; current;
          ListIterator(ListNode&lt;T&gt; head) {
              current = head;
          }
          public boolean hasNext() {
              return (current != null);
          }
     ...
  </code></pre>