Hi, I am passing in an object into a method(object can an instance of three different classes A,B,C and these have no common interface or abstract class). I do not want to repeat the code for each instance, how can I use reflection to make it one setter for all the objects?
Now I caught Exception, but in real life situations you will want to catch all exceptions separately: NoSuchMethodException, IllegalAccessException and InvocationTargetException.
Please note that I'd prefer your old solution; sure, it may be more tedious to write, but it is less error prone and more clear. Instead of trying to call a method on an object without knowing it actually has the method, you are actually making sure it has the method first. Also, you show that you know what object types you are expecting. [ May 01, 2008: Message edited by: Rob Prime ]
Rob, Thanks for your response. After thinking about your suggestion of keeping the old code I plan to stick to it so that its more clear/easy to understand and no danger of not finding a method on a class.