Created
April 9, 2012 15:25
-
-
Save blangel/2344215 to your computer and use it in GitHub Desktop.
native java reflection field setting
This file contains 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
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