Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > "Incompatible types" error though types are same generic type

Reply
Thread Tools

"Incompatible types" error though types are same generic type

 
 
wdh3rd@gmail.com
Guest
Posts: n/a
 
      04-14-2007
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.

 
Reply With Quote
 
 
 
 
wdh3rd@gmail.com
Guest
Posts: n/a
 
      04-14-2007
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>.

 
Reply With Quote
 
 
 
 
Peter Sestoft
Guest
Posts: n/a
 
      04-14-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
wdh3rd@gmail.com
Guest
Posts: n/a
 
      04-15-2007

> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Argument type of function and safe types and types, arguments canhandle safely ittium C++ 4 12-09-2011 11:05 AM
not just generic type programming,but also parallism generic syntaxprogramming?? minlearn C++ 2 03-13-2009 05:17 PM
Type inference with mutually recursive generic types Niklas Matthies Java 0 10-24-2006 01:58 PM
No generic type checking at all for raw types? Christopher Benson-Manica Java 1 10-10-2006 08:29 PM
2 PIX Same COnfig, though 1 not connected to 'real' outside? Does not work? Scott Townsend Cisco 3 03-23-2006 04:43 PM



Advertisments