tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Tools and Libs > Commons Lang3 > Reflection > Read Static Field

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.

File Name  :  
com/bethecoder/tutorials/commons_lang/tests/reflections/ReadStaticFieldTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
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[] argsthrows IllegalAccessException {

    Integer max = (IntegerFieldUtils.readStaticField(Integer.class, "MAX_VALUE");
    System.out.println(max);

    Integer min = (IntegerFieldUtils.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]



 
  


  
bl  br