How to use getMethod() with primitive types?
Solution 1:
There's just an int.class
.
Class[] types = { int.class, Object.class };
An alternative is Integer.TYPE
.
Class[] types = { Integer.TYPE, Object.class };
The same applies on other primitives.
Solution 2:
The parameter of the method is a primitive short
not an Object Short
.
Reflection will not find the method because you specified an object short. The parameters in getMethod()
have to match exactly.
EDIT: The question was changed. Initially, the question was to find a method that takes a single primitive short.