gonbe is a simple wrapper for the java.lang.reflect package.
This project is similar to jOOR, but with the following key differences:
ObjectMirror
andClassMirror
are represented with separate types, whereas jOOR conflates the two (under a nameReflect
).- The
get
,set
, andcall
methods onMirror
have their m-suffixed counterparts which wrap the output inMirror
. e.g.Mirror.on("hello").call("charAt", 0)
returns'h'
whereasMirror.on("hello").callM("charAt", 0)
returnsMirror.on('h')
. - The implementation makes extensive use of functionaljava, though that's irrelevant from the user point of view.
// With java.lang.reflect:
PrivateObject privateObject = new PrivateObject("The Private Value");
Class<?>[] paramTypes = { int.class, String.class };
Object[] args = { 3, "Hello" };
Method privateStringMethod = PrivateObject.class.getDeclaredMethod("getPrivateString", paramTypes);
privateStringMethod.setAccessible(true);
String returnValue = (String) privateStringMethod.invoke(privateObject, args);
// With gonbe:
PrivateObject privateObject = new PrivateObject("The Private Value");
String returnValue = Mirror.on(privateObject).call("getPrivateString", 3, "hello");