how can I implement Comparable more than once?

Posted by codeman73 on Stack Overflow See other posts from Stack Overflow or by codeman73
Published on 2010-04-21T18:27:48Z Indexed on 2010/04/21 19:23 UTC
Read the original article Hit count: 291

Filed under:
|
|

I'm upgrading some code to Java 5 and am clearly not understanding something with Generics. I have other classes which implement Comparable once, which I've been able to implement. But now I've got a class which, due to inheritance, ends up trying to implement Comparable for 2 types. Here's my situation:

I've got the following classes/interfaces:

interface Foo extends Comparable<Foo>

interface Bar extends Comparable<Bar>

abstract class BarDescription implements Bar

class FooBar extends BarDescription implements Foo

With this, I get the error 'interface Comparable cannot be implemented more than once with different arguments...'

Why can't I have a compareTo(Foo foo) implemented in FooBar, and also a compareTo(Bar) implemented in BarDescription? Isn't this simply method overloading?

© Stack Overflow or respective owner

Related posts about java

Related posts about generics