I want to have an abstract class that has an abstract method, say abstract void compare()
. But the parameters it takes should vary according to different implementations in different subclasses. I wonder what is the right way to do this?
I cannot overload it by writing different signatures of it in the abstract class itself, because if I do so, any of its subclasses would need to implement all the versions, which is not what I want. Thanks.
Assuming that each version of compare()
will all have the same number of parameters (which they should), you could use generics so that subclasses can define what the types of the parameters are.
abstract <I, J> void compare(I arg1, J arg2);