I am setting visibility on and off for many elements. Now I want to create a method that will receive an Object, assuming that every class top parent is Object, that would be good enough? If that’s what I should do, how should I cast them?
And I want to check if the received objects contains a setVisibility method and if it does perform some actions.
Should I just try and run the method and catch an exception? sounds dumb.
What should I do then?
See the first example here, http://java.sun.com/developer/technicalArticles/ALT/Reflection/
You basically get the class variable for object you are looking at, call the
getDeclaredMethods()to get a array of method names. You can then check to see if the method name exists on the class.Further down the page there is an example for invoking the method as well.