[英]Method with primitive argument using PrivilegedAccessor
Within my Junit, I am trying to execute a Method using PrivilegedAccessor
as following but getting NoSuchMethodException: Invalid Method getInsurance
- 在我的Junit中,我尝试使用
PrivilegedAccessor
执行以下方法,但得到NoSuchMethodException: Invalid Method getInsurance
PrivilegedAccessor.invokeMethod(InsuranceRetriever,
"getInsurance", new Object[] { code}, new Class[] {
Long.class});
Following is the tested method declaration. 以下是经过测试的方法声明。
private InsObj getInsurance(long code)
*Please note here that i am passing Long.class whereas the real argument is primitive long. *请注意,我正在传递Long.class,而实际参数是原始long。 How to pass primitive argument.
如何传递原始参数。
Try this: 尝试这个:
PrivilegedAccessor.invokeMethod(InsuranceRetriever,
"getInsurance", new Object[] { code },
new Class[] { Long.TYPE });
Explanation: 说明:
The class objects for the primitive types are found under the TYPE static final constant in each of the java.lang objects for each of the primitive types. 基本类型的类对象可在每种基本类型的每个java.lang对象的TYPE静态最终常量下找到。
Boolean.TYPE
, Integer.TYPE
, Byte.TYPE
, Short.TYPE
, Long.TYPE
etc. Boolean.TYPE
, Integer.TYPE
, Byte.TYPE
, Short.TYPE
, Long.TYPE
等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.