Reputation: 1022
I have some 3rd-party API with method someFn(int code, int[] data)
.
How can I express types (particulary array-typed argument) outside API container (interface class) for usage in Class.getMethod(name, Integer.class, ???.class);
? How can I describe argument of array type properly?
As far as I know, I may use workaround like, but is there a better way of doing this?
class C { void f(int[] a) {} } }
C.class.getDeclaredMethods()[0].getParameterTypes()[0]
Thanks in advance
Upvotes: 0
Views: 1086
Reputation: 34367
Class.getMethod(name, Integer.class, int[].class);
int[]
is class and hence int[].class
is a valid statement to refer int array class.
Upvotes: 2
Reputation: 14728
You can use int[].class
to get the class literal of int []
and pass it to Class.getMethod
:
Class.getMethod(name, Integer.class, int[].class);
Upvotes: 3