Created
December 3, 2013 14:10
-
-
Save zviri/7769761 to your computer and use it in GitHub Desktop.
Common tasks tasks which can be done via reflection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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