As in previous sentences, you can change your update to.
public void update(Observable o, Object arg) { try{ Method update = getClass().getMethod(o.getClass(), Object.class); update.invoke(this, o, arg); } catch(Exception e) { // log exception } }
This way you can add one method
public void update(A a, Object arg); public void update(B b, Object arg); public void update(C c, Object arg);
for every type you want to watch. Unfortunately, you need to know the specific concrete type of Observable. However, you can change the reflections to allow interfaces, etc.
Peter Lawrey
source share