I have a superclass which implements the Comparable
Interface and overrides the compareTo()
method. One subclass of this superclass has to implement it's own compareTo()
method but I'm not able to override the compareTo()
method of the superclass due to the name clash error.
public abstract class Superclass<T> implements Comparable<T> {
public int compareTo(T bo) { };
}
public class Subclass extends Superclass<Subclass> {
public <T> int compareTo(T bo) { }; // I get the name clash error here
}
To solve this problem I tried to make the subclass generic too (see: Java Generics name clash, method not correctly overridden), but either I did it wrong or this doesn't work:
public abstract class Superclass<T> implements Comparable<T> {
public int compareTo(T bo) { };
}
public class Subclass<T> extends Namable<Subclass<?>> {
public int compareTo(T bo) { }; // I get the name clash error here
}
So, how can I override the compareTo()
method of Superclass?