开发者

What class parameter type should should be passed for variable arg Object array

开发者 https://www.devze.com 2023-02-15 09:12 出处:网络
If I have to pass an Object... var arguments parameter as input 开发者_高级运维to the Method.invoke call, what should I specify as the parameter type for the Class.getMethod callClass.getMethod(\"meth

If I have to pass an Object... var arguments parameter as input 开发者_高级运维to the Method.invoke call, what should I specify as the parameter type for the Class.getMethod call


Class.getMethod("methodName", Object[].class)

UPDATE How to work with varargs and reflection provides more precise answer by Bozho


You're best off if you can specify the Classes that represent the real formal parameters of the method, as in its declaration. If you can't, the rules for resolution (at the link you provide) are not the most transparent.

0

精彩评论

暂无评论...
验证码 换一张
取 消