Reputation: 35
I am trying to use the .getClass()
method in java to mimic the getattr
method of python to find a method with the same name as a input string "methodName", but I am getting an error saying
Method cannot be resolved as a type
Here is the code:
Method func = exampleObject.getClass().getMethod("methodName", Object[].class);
func.invoke(exampleObject, args);
Upvotes: 1
Views: 5536
Reputation: 10662
Looks like you forget the import for "Method"?
import java.lang.reflect.Method;
Upvotes: 5