Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to convert a raw Comparator type to a generic type.

807598Jul 21 2006 — edited Jul 21 2006
I have a situation requiring a generic Comparator type, for now this has been implemented using a raw Comparator type, but I would like to rewrite this to a genuine generic type, unfortunately without success yet. Basically what I would like to achieve is something like:
public class Test
{
    public int myCompare( Comparator<? extends Object> cmp, Object e1, Object e2 )
    {
        return cmp.compare(e1,e2);
    }
}
I have tried several versions of the unbounded wildcard, but they all seem to result in some kind of compiler error, the above attempt results in something like:
"The method compare(capture-of ? extends Object, ... is not applicable for the arguments (Object, Object )."
Question is how to write this down properly?

Regards,
Wieant
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 18 2006
Added on Jul 21 2006
3 comments
242 views