Advertisement
Guest User

FieldAccessible.java

a guest
Apr 14th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. package ToDo;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.lang.reflect.Modifier;
  5.  
  6.  
  7. public class FieldAccessible {
  8.     public static class MyClass {
  9.         public String theField;
  10.     }
  11.  
  12.     public static void main(String[] args) throws Exception {
  13.         MyClass myClass = new MyClass();
  14.         Field field1 = myClass.getClass().getDeclaredField("theField");
  15.  
  16.         field1.setAccessible(true);
  17.         System.out.println(field1.get(myClass));
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement