简体   繁体   中英

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

如果我必须传递一个Object ... var arguments参数作为Method.invoke调用的输入,我应该指定什么作为Class.getMethod调用的参数类型

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

更新 如何使用varargs和反射提供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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM