Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

"Incompatible types" error though types are same generic type

Thread view: 
wdh3rd@gmail.com - 14 Apr 2007 21:14 GMT
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.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.