Skip to content

Instantly share code, notes, and snippets.

@zviri
Created December 3, 2013 14:10
Show Gist options
  • Save zviri/7769761 to your computer and use it in GitHub Desktop.
Save zviri/7769761 to your computer and use it in GitHub Desktop.
Common tasks tasks which can be done via reflection
import java.lang.reflect.Field;
public class ReflectionUtils {
// least invasive method of obtaining protected/private field value
private static <T> T getPrivateFieldValue(Object object, String fieldName) throws Exception {
Field field = object.getClass().getDeclaredField(fieldName);
field.setAccessible(true);
T fieldValue = (T) field.get(object);
field.setAccessible(false);
return fieldValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment