简体   繁体   中英

Call private method in seam component

Is there a way to invoke private methods in Seam Component. I used the following code but I found that there is no private methods in declared methods. So, I get NoSuchMethodException .

Object obj = Component.getInstance("myComponent");
Method myMethod = obj.getClass.getDeclaredMethod("myPrivateMethod",String.class);
myMethod.invoke(obj,"myParameter");

Make setAccessible true .

 Method myMethod = obj.getClass.getDeclaredMethod("myPrivateMethod",String.class);
 method.setAccessible(true);
 Object r = myMethod.invoke(obj,"myParameter");

A value of true indicates that the reflected object should suppress Java language access checking when it is used. for more look in API .

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