"Incompatible types" error though types are same generic type

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

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

  2. 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>.
     
    , Apr 14, 2007
    #2
    1. Advertising

  3. writes:

    > 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 {
    > ...
    > } //end Node
    >
    > private class CircularLinkedIterator<E> implements dataStructs.Iterator<E> {
    > ...
    > public E get () {
    > return current.element(); //error is at this line
    > }
    > } //end CircularLinkedIterator
    >
    > }//end CircularLinkedList


    You have two distinct type parameters both called E.

    Peter
     
    Peter Sestoft, Apr 14, 2007
    #3
  4. Guest


    > 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.
     
    , Apr 15, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Goche
    Replies:
    1
    Views:
    843
    Ranganath Kini
    Feb 9, 2006
  2. Dimitris Mandalidis

    Re: malloc & incompatible types in assignment

    Dimitris Mandalidis, Aug 31, 2003, in forum: C Programming
    Replies:
    4
    Views:
    1,036
    Al Bowers
    Aug 31, 2003
  3. Dennis Schulz

    error: incompatible types in asignment

    Dennis Schulz, May 26, 2004, in forum: C Programming
    Replies:
    2
    Views:
    492
    Emmanuel Delahaye
    May 26, 2004
  4. Richard Bos

    error: incompatible types in assignment

    Richard Bos, Jul 25, 2006, in forum: C Programming
    Replies:
    8
    Views:
    1,522
    Mark McIntyre
    Jul 25, 2006
  5. minlearn
    Replies:
    2
    Views:
    485
    red floyd
    Mar 13, 2009
Loading...

Share This Page