Read Static Field
Apache Commons Lang 3.0 is a java library with lot of utilities and reusable components.
This requires the library commons-lang3-3.0.1.jar to be in classpath.
The following example shows using FieldUtils.readStaticField() API.
package com.bethecoder.tutorials.commons_lang.tests.reflections;
import java.util.Arrays;
import org.apache.commons.lang3.reflect.FieldUtils;
public class ReadStaticFieldTest {
/**
* @param args
* @throws IllegalAccessException
*/
public static void main ( String [] args ) throws IllegalAccessException {
Integer max = ( Integer ) FieldUtils.readStaticField ( Integer.class, "MAX_VALUE" ) ;
System.out.println ( max ) ;
Integer min = ( Integer ) FieldUtils.readStaticField ( Integer.class, "MIN_VALUE" ) ;
System.out.println ( min ) ;
char [] digits = ( char []) FieldUtils.readStaticField ( Integer.class, "digits" , true ) ;
System.out.println ( Arrays.toString ( digits )) ;
}
}
It gives the following output,
2147483647
-2147483648
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, g, h, i, j, k, l, m, n,
o, p, q, r, s, t, u, v, w, x, y, z]