DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Obtaining The Value Of A Public Static Field By Reflexion
// Obtaining the value of a static public constant of a class, here Boolean for example
Object returnedObj = null;
try {
Class clazz = Class.forName("java.lang.Boolean");
returnedObj = clazz.getField("TRUE").get(clazz);
assert java.lang.Boolean.TRUE == returnedObj : "wrong returned object";
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return returnedObj;





