Skip to content

Instantly share code, notes, and snippets.

@blangel
Created April 9, 2012 15:25
Show Gist options
  • Save blangel/2344215 to your computer and use it in GitHub Desktop.
Save blangel/2344215 to your computer and use it in GitHub Desktop.
native java reflection field setting
Field nameField;
try {
nameField = getClass().getDeclaredField("name");
} catch (NoSuchFieldException nsfe) {
throw new AssertionError("No field named 'name'");
}
nameField.setAccessible(true);
try {
nameField.set(this, getClass().getName());
} catch (IllegalAccessException iae) {
throw new AssertionError(iae);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment