Created
April 25, 2023 09:23
-
-
Save maudmcok/20ddad42c72e17fedc01e7ca56449847 to your computer and use it in GitHub Desktop.
Method to get the value of a private static final field of a class Java.
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
/** | |
* Method to get the value of a private static final field of a class. | |
*/ | |
protected String getStaticFinalStringValue(Class<?> targetClass, String fieldName) throws NoSuchFieldException, IllegalAccessException { | |
Field field = targetClass.getDeclaredField(fieldName); | |
field.setAccessible(true); | |
return (String) field.get(null); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment