java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at TestReflect.showMethods(TestReflect.java:22) at TestReflect.main(TestReflect.java:7)
HI All, How can i call only user defined methods only not the Object class methods. when i call invoke method it is calling my class methods as well Object class methods. How can i restrict Object class methods.
But i don't want the object class methods to execute.
Your code iterates through all methods; if that's not what you want, then don't do it
The Method class has the getDeclaringClass method which will tell you for any method the class in which it is declared. If that's not your own class (i.e., the method was inherited), then you can skip it. At least that's how I read the javadocs, I've never used the method.