Search code examples
javagenericscomparable

extend Comparable generic in a final class


I try to extend Comparable<> in my final class but I have no clue why it throughs this error.

public final class Identifier extends Comparable<Identifier> {

...

}

ERROR: The type Comparable cannot be the superclass of Identifier; a superclass must be a class

But isnt Comparable a class? I don't get it.

Thanks for your help


Solution

  • No, it's an interface. You implement interfaces, you don't extend them. You need

    public final class Identifier implements Comparable<Identifier> {
      ...
    }