Within my Junit, I am trying to execute a Method using PrivilegedAccessor
as following but getting 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. 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. Boolean.TYPE
, Integer.TYPE
, Byte.TYPE
, Short.TYPE
, Long.TYPE
etc.
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.