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 / July 2005

Tip: Looking for answers? Try searching our database.

[unchecked] unchecked call to compareTo(T) as a member of the raw type java.lang.Comparable

Thread view: 
Elliot - 10 Jul 2005 07:18 GMT
Hello World!

This is my code:

public class Queue implements Iterable
{
       //...
    private class QueueNode implements Comparable<QueueNode>
    {
        Comparable data;
               //...
        public int compareTo(QueueNode node)
        {
            return data.compareTo(node.getData());
        }
    }
}

This is the warning:

Queue.java:25: warning: [unchecked] unchecked call to compareTo(T) as a
member of the raw type java.lang.Comparable
                       return data.compareTo(node.getData());
                                            ^
1 warning

I hope to receive answers to two questions.

1. First, will someone that is familiar with generics please modify the
syntax involved with the generics of this code so that it will compile
successfully and without any warnings?

2. Second, As I was trying to figure this out on my own I read
somewhere that because of generics the Comparable interface is not the
same thing as the Comparable<T> interface. I am hoping that someone
will either explain the difference to me or point me to documentation
somewhere that will explain the difference between these two
interfaces. And if you understand the difference between the two
interfaces, do you recommend that I use Comparable data or
Comparable<?> data inside the QueueNode object? And if your
recommendation is that I use Comparable<?>, will you please give me
some information about the ? in the generics syntax.

3. Thank you for taking time to read this and I appreciate your help if
you decide to give it.

Elliot
Stefan Schulz - 10 Jul 2005 09:14 GMT
BTW: Are you sure you do not mean
public class Queue implements Iterable<Something>?

Or even
public class Queue<T> implements Iterable<T>?

> public class Queue implements Iterable
> {
>         //...
>     private class QueueNode implements Comparable<QueueNode>
>     {
>         Comparable data;

If your data is of Type DataType, replace this with:

               Comparable<DataType> data;

Or if you where gunning at a generic class

               Comparable<? super T> data;
>                 //...
>         public int compareTo(QueueNode node)
[quoted text clipped - 17 lines]
> syntax involved with the generics of this code so that it will compile
> successfully and without any warnings?

See above. The call to compareTo uses the raw Comparable type, not
Comparable<Something>

Signature

You can't run away forever,
But there's nothing wrong with getting a good head start.
          --- Jim Steinman, "Rock and Roll Dreams Come Through"
         



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.