aaadawg
aaadawg

Reputation: 35

java: Method cannot be resolved to a type

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

Answers (1)

Florian Schaetz
Florian Schaetz

Reputation: 10662

Looks like you forget the import for "Method"?

import java.lang.reflect.Method;

Upvotes: 5

Related Questions