Invoking Methods
Invoking a static method:
Class clazz;
Object returnValue = new Mirror().on(clazz).invoke().method("methodName")
.withArgs(value1, value2);
Invoking an instance method:
Object target;
Object returnValue = new Mirror().on(target).invoke().method("methodName").withoutArgs();
You can also pass a java.lang.reflect.Method instead of a methodName String:
Invoking an instance method:
Method aMethod;
Object target;
Object returnValue = new Mirror().on(target).invoke().method(aMethod)
.withArgs(value1, value2);
Invoking a setter method:
Field field;
Object target;
new Mirror().on(target).invoke().setterFor(field).withValue(value1);
new Mirror().on(target).invoke().setterFor("fieldName").withValue(value1);
Invoking a getter method:
Field field
Object target;
Object returnValue = new Mirror().on(target).invoke().getterFor(field);
Object returnValue = new Mirror().on(target).invoke().getterFor("fieldName");