-
lookup of the class of the object to access
Class<?> clazz = object.getClass();
-
wrapping of param types into arrays
Class<?>[] paramTypes = new Class<?>[]{char[].class};
-
lookup of the member to access
Method m = clazz.getDeclaredMethod("callExample", args);
-
enabling access for private methods/fields
m.setAccessible(true);
-
wrapping arguments into arrays
Object[] args = new Object[]{"chars".toCharArray()};
-
indirectly setting, getting, invoking members
Object result = m.invoke(object, args);
-
converting the result type
int intResult = ((Integer) result).intValue();
-
Just define the interface
interface Example { int callExample(char[] characters); }
-
Then bind it:
Example example = XRayInterface.xray(object).to(Example.class);
-
And call it:
int intResult = example.callExample("chars".toCharArray());