"Incompatible types" error though types are same generic type

Discussion in 'Java' started by wdh3rd, Apr 14, 2007.

  1. wdh3rd

    wdh3rd Guest

    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, Apr 14, 2007
    1. Advertisements

  2. wdh3rd

    wdh3rd Guest

    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>.
    wdh3rd, Apr 14, 2007
    1. Advertisements

  3. You have two distinct type parameters both called E.

    Peter Sestoft, Apr 14, 2007
  4. wdh3rd

    wdh3rd Guest

    Thanks. I hadn't thought of that. I made the CircularLinkedIterator
    non-generic and everything seems to be kosher now.
    wdh3rd, Apr 15, 2007
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.