Java generic Comparable where subclasses can't compare to eachother
- by dege
public abstract class MyAbs implements Comparable<MyAbs>
This would work but then I would be able to compare class A and B with each other if they both extend MyAbs. What I want to accomplish however is the exact opposite.
So does anyone know a way to get the generic type to be the own class? Seemed like such a simple thing at first...
Edit:
To explain it a little further with an example. Say you have an abstract class animals, then you extend it with Dogs and ants.
I wouldn't want to compare ants with Dogs but I however would want to compare one dog with another. The dog might have a variable saying what color it is and that is what I want to use in the compareTo method. However when it comes to ants I would rather want to compare ant's size than their color.
Hope that clears it up. Could possibly be a design flaw however.