I have a class that uses XML and reflection to return Objects to another class. Normally these objects are sub fields of an external object, but occasionally its something I want to generate on the fly. I've tried something like this but to no avail. I believe that's because JAVA won't allow you to access private methods for reflection.
Element node = outerNode.item(0);
String methodName = node.getAttribute("method");
String objectName = node.getAttribute("object");
if("SomeObject".equals(objectName))
object = someObject;
else
object = this;
method = object.getClass().getMethod(methodName,(Class[])null);
if the method provided is private it fails with a no such method. I could solve it by making the method public, or making another class to derive it from.
Long story short, I was just wondering if there was a way to access a private method via reflection.