http://projetos.vidageek.net/mirror/mirror/
Mirror
Mirror was created to bring light to a simple problem, usually named ReflectionUtil, which is on almost all projects that rely on reflection to do advanced tasks.
Dealing with Java Reflection API is painful. Ask anyone you know that uses reflection and he will tell you it's really unpleasant getting yourself around it.
Take a look at the following code:
//Let's just set a field value. Should be a simple task, right?
//"target" is the object containing the field whose value you want to set.
Field toSet = null;
for (Field f : target.getClass().getDeclaredFields()) {
//Get all fields DECLARED inside the target object class
if (f.getName().equals("field")) {
toSet = f;
}
}
if (toSet != null && (toSet.getModifiers() & Modifier.STATIC) == 0) {
toSet.setAccessible(true);
toSet.set(target, value);
}
网友评论