I am trying to use reflection to call a method whose name and arguments are known at runtime, and I fail with an IllegalAccessException .
This is an object that is an instance of a non-public class that implements an open interface, and I have a brain spasm trying to remember the correct way to call such a method.
public interface Foo { public int getFooValue(); } class FooImpl implements Foo { @Override public int getFooValue() { return 42; } } Object foo = new FooImpl();
Given the foo object, how would I call foo.getFooValue () reflexively?
If I look at the results of foo.getClass().getMethods() , this should work, but I think it raises an IllegalAccessException . Is this the case when I need to call getDeclaredMethods() ? Or do I need to go through public interfaces / superclasses and call getDeclaredMethods there?
source share