[英]Java: How to pass typed-array class as parameter?
I have some 3rd-party API with method someFn(int code, int[] data)
. 我有一些使用方法
someFn(int code, int[] data)
的第三方API。
How can I express types (particulary array-typed argument) outside API container (interface class) for usage in Class.getMethod(name, Integer.class, ???.class);
我如何在API容器(接口类)外部表达类型(尤其是数组类型的参数)以用于
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 提前致谢
你可以用int[].class
以获取类文字的int []
并把它传递给Class.getMethod
:
Class.getMethod(name, Integer.class, int[].class);
Class.getMethod(name, Integer.class, int[].class);
int[]
是类,因此int[].class
是引用int数组类的有效语句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.