I have a Dummy class that has a private method called sayHello. I want to call sayHello from outside Dummy. I think it should be possible with reflection but I get an IllegalAccessException. Any ideas???
I have a Dummy class that has a private method called sayHello . I
Share
use
setAccessible(true)on your Method object before using itsinvokemethod.If someone is interested in invoking methods with parameters see How do I invoke a Java method when given the method name as a string?, specifically answer like https://stackoverflow.com/a/30671481.
Just don’t forget to add
setAccessible(true)while invokingprivatemethods.