Hello everyone,
Even though two methods both use the generic return type - E - I'm
getting an error saying that they're incompatible types. Here's the
truncated code:
public class CircularLinkedList<E> extends AbstractList<E> {
private class Node {
private E element;
public E element () {
return this.element;
}
} //end Node
private class CircularLinkedIterator<E> implements
dataStructs.Iterator<E> {
private Node current;
public Node current () {
return this.current;
}
public E get () {
return current.element(); //error is at this line
}
} //end CircularLinkedIterator
}//end CircularLinkedList
The error that I receive reads:
Error: incompatible types
found: E
required: E
I'm at a loss for understanding why the same generic types could
render an incompatible types error. Can anyone shine some Java
wisdom?? Thanks for any help anyone can offer.
wdh3rd@gmail.com - 14 Apr 2007 21:17 GMT
Sorry, I forgot to mention that the AbstractList<E> that is being
extended by the CircularLinkedList<E> is not the AbstractList<E> from
the Java API, but my own AbstractList<E>.
Peter Sestoft - 14 Apr 2007 22:54 GMT
> Even though two methods both use the generic return type - E - I'm
> getting an error saying that they're incompatible types. Here's the
[quoted text clipped - 13 lines]
>
> }//end CircularLinkedList
You have two distinct type parameters both called E.
Peter
wdh3rd@gmail.com - 15 Apr 2007 15:36 GMT
> You have two distinct type parameters both called E.
>
> Peter
Thanks. I hadn't thought of that. I made the CircularLinkedIterator
non-generic and everything seems to be kosher now.