I have an abstract class UserdataUpdater which extends Updater
Updater has a method declaration
public abstract void processRow (Cluster cluster, IAppendOnlyData row);
Is there anyway to modify this method declaration inside UserdataUpdater to make it more specific, like
public abstract void processRow (Cluster cluster, IUserData row);
IUserData extends IAppendOnlyData, because I want classes that extends UserdataUpdater to only take IUserData
No, you can’t. This would break the contract of the superclass, which says: this method accepts a IAppendOnlyData as second argument.
Remember that an instance of a subclass is also an instance of its superclass. So anyone could refer to the subclass instance as its superclass, and call the base method, passing a IAppendOnlyData, without knowing that the instance is actually a subclass instance.
Read more about the Liskov substitution principle.
The only way to do that is to make the superclass generic: