Results 1 to 4 of 4
  1. #1
    Muskar is offline Member
    Join Date
    Nov 2010
    Posts
    73
    Rep Power
    0

    Default Eclipse warning to type 'Comparable'

    Hey.

    I'm just wondering, when I'm making e.g. a method like this:

    Java Code:
    public Comparable methodName (Comparable[] a) {...}
    it gives me a warning on both Comparables saying the following:

    Comparable is a raw type. References to generic type Comparable<T> should be parameterized
    And it suggests that I do either:
    • Put types arguments (Comparable <?>)
    • Infer Generic Type Arguments (I let it do this automatically and it didn't seem like anything changed)


    I researched a bit on raw types and tried several different versions, e.g.:
    Java Code:
    <T extends Comparable <? super T>>

    and

    Java Code:
    <T extends Comparable <T>>
    but neither worked.
    Anyone know what I should write to make it take all Comparables (just as it does but without that warning)?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,190
    Blog Entries
    7
    Rep Power
    24

    Default

    Comparable is a generic interface so if a class C wants to implement it, it should implement (most likely, there are very rare exceptions to this rule) Comparable<C> and compare an object type C (this) with another object C.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

  3. #3
    Muskar is offline Member
    Join Date
    Nov 2010
    Posts
    73
    Rep Power
    0

    Default

    Quote Originally Posted by JosAH View Post
    Comparable is a generic interface so if a class C wants to implement it, it should implement (most likely, there are very rare exceptions to this rule) Comparable<C> and compare an object type C (this) with another object C.

    kind regards,

    Jos
    So that's the only thing the warning is about?
    If that's the case, I suppose I'll just add a @SuppressWarnings("rawtypes") to it then.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,190
    Blog Entries
    7
    Rep Power
    24

    Default

    Quote Originally Posted by Muskar View Post
    So that's the only thing the warning is about?
    If that's the case, I suppose I'll just add a @SuppressWarnings("rawtypes") to it then.
    Yep, that's a possibility (it's only a warning after all); besides: arrays don't go well with generics.

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. Got hit by the Comparable block again, help pls.
    By niu_niu in forum New To Java
    Replies: 7
    Last Post: 06-24-2010, 09:49 AM
  2. Comparable Interface
    By Yelrubk in forum New To Java
    Replies: 3
    Last Post: 04-28-2010, 02:46 PM
  3. Replies: 1
    Last Post: 03-14-2010, 11:03 PM
  4. Creating a Comparable object
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-15-2008, 07:38 PM
  5. interface Comparable<T> problem
    By Lennon-Guru in forum New To Java
    Replies: 3
    Last Post: 03-05-2008, 01: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
  •