Is there a way to define a default, or fallback, overriding method that can handle any unhandled methods?
The reason I ask this is because I’ve made a class to override a class in a function library that is constantly subject to change. In order to successfully compile the class, all methods must be defined and overridden, but I don’t really want to be recoding my class every time there is an update.
Here’s an example of what’s written:
public class CommandSignsPlayerProxy implements Player {
private Player proxy;
private boolean silent;
public CommandSignsPlayerProxy(Player targetPlayer) {
this.proxy = targetPlayer;
}
public boolean isSilent() {
return silent;
}
public void setSilent(boolean silent) {
this.silent = silent;
}
@Override
public void abandonConversation(Conversation conversation, ConversationAbandonedEvent details) {
proxy.abandonConversation(conversation, details);
}
// This function is basically the only one that NEEDS overriding
@Override
public void sendMessage(String message) {
if (!silent)
proxy.sendMessage(message);
}
@Override
public void setFlySpeed(float arg0) throws IllegalArgumentException {
proxy.setFlySpeed(arg0);
}
}
In the real code, there is another 50+ overridden functions. So is there a way to make an automatic handler that overrides function_name() with proxy.function_name()?
A Dynamic Proxy may be able to do this. From the documentation: