Results 1 to 4 of 4
  1. #1
    dylandrop is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default comparable interface, generic types

    So I'm trying to learn to use interfaces, and I'm encountering this problem when trying to write a generic selection sort. Eclipse's warning is this:"Comparable is a raw type. References to generic type Comparable<T> should be parameterized." What does this mean/how do I go about fixing this?

    Java Code:
    public class SelectSort
    {
    
    public static void selectSort(Comparable[] objects)
       {
            int min;
            Comparable temp;
    
            for(int i=0; i<objects.length-1;i++)
            {
               min=i;
               for(int j=i+1;j<objects.length;j++)
               {
                  if(objects[j].compareTo(objects[min])<0)
                    min=j;
               } // end inner for loop
               temp=objects[min];
               objects[min]=objects[i];
               objects[i]=temp;
    
    
    
               } 
       } 
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    That's a warning, not an error, and you don't need to change your code for your code to work. To get rid of the warning, you can likely use an annotation (but I'm not sure which one). Otherwise, if you want to use generic typing to give your code compile-time type checking, then check out the tutorials on this at the Java tutorials.

  3. #3
    dylandrop is offline Member
    Join Date
    Apr 2011
    Posts
    6
    Rep Power
    0

    Default

    Ok thanks - yeah I know it was a warning, I just didn't know where to find info on fixing it. Thanks though

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dylandrop View Post
    Ok thanks - yeah I know it was a warning, I just didn't know where to find info on fixing it. Thanks though
    The generics tutorials start here: Generics

Similar Threads

  1. I don't understand comparable Interface Please help me
    By chathura87 in forum New To Java
    Replies: 11
    Last Post: 03-01-2011, 06:48 AM
  2. Comparable Interface
    By Yelrubk in forum New To Java
    Replies: 3
    Last Post: 04-28-2010, 02:46 PM
  3. Replies: 6
    Last Post: 04-28-2010, 12:49 AM
  4. Can generic types implement an interface?
    By jdgallag in forum New To Java
    Replies: 3
    Last Post: 10-30-2008, 04:07 AM
  5. interface Comparable<T> problem
    By Lennon-Guru in forum New To Java
    Replies: 3
    Last Post: 03-05-2008, 12:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •