I have lots of object defined in the system, perhaps 1000 objects,
and some of them have this method:
public Date getDate();
Is there anyway I can do something like this:
Object o = getFromSomeWhere.....;
Method m = o.getMethod("getDate");
Date date = (Date) m.getValue();
If you can make them all implement an interface, that would certainly be the best option. However, reflection will also work, and your code was nearly there:
(There’s a bunch of exceptions you’ll need to handle, admittedly…)
For a full example: