Reputation: 29693
Let's I have method
someMethod(int, String)
and I want to invoke it by method invoke(Object, Object[]) of class Method. Can I do it? If I can then how?
Upvotes: 2
Views: 2181
Reputation: 20229
You can, use invoke(Instance of Object containing Method, 5, "foo")
Upvotes: 3
Reputation: 115328
You can do it as following:
MyClass.class.getMethod(int.class, String.class).invoke(obj, 1, "hello")
where obj
is a instance of your class.
If your method is static you can pass null
instead of obj
.
Upvotes: 3