how can I implement Comparable more than once?

后端 未结 3 811
情歌与酒
情歌与酒 2020-12-31 05:15

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 i

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-31 05:51

    Generics don't exist after bytecode has been compiled.

    Restrictions from this: You can't implement / extend two or more interfaces / classes that would be same without the generic parameter and are different with the generic parameter.

    What you could do if you really really want type safety is:

    interface Foo> extends Comparable
    interface Bar> extends Comparable
    abstract class BarDescription> implements Bar
    class FooBar extends BarDescription implements Foo
    

提交回复
热议问题