What is the instanceof
operator used for? I\'ve seen stuff like
if (source instanceof Button) {
//...
} else {
//...
}
You could use Map to make higher abstraction on instance of
private final Map> actions = new HashMap<>();
Then having such map add some action to it:
actions.put(String.class, new Consumer() {
@Override
public void accept(String s) {
System.out.println("action for String");
}
};
Then having an Object of not known type you could get specific action from that map:
actions.get(someObject).accept(someObject)