Your mistake is in your question. You do not need to implement public int compareTo(BaseClass arg) . You must implement "public int compareTo (YourClass arg)".
In this case, you do not need to use instanceof and do the translation. That's why generics were introduced: to avoid casting.
But if you still want to use the base class as an argument, do at least the following:
public class Test { } class SubTest <T extends Test> implements Comparable<T> { @Override public int compareTo(T o) {
At the very least, this approach requires the argument to be a subclass of your base class.
Alexr source share