Skip to content

Instantly share code, notes, and snippets.

@maudmcok
Created April 25, 2023 09:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maudmcok/20ddad42c72e17fedc01e7ca56449847 to your computer and use it in GitHub Desktop.
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.
/**
* 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