waltermilner

Untitled

Nov 17th, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. class MyClass {
  2.  
  3.   int x = 5;
  4.   static double d = 43.2;
  5. }
  6.  
  7. public class Test {
  8.  
  9.   public static void main(String[] args) {
  10.     MyClass mc = new MyClass();
  11.     Class c = mc.getClass();
  12.     Field[] f = c.getDeclaredFields();
  13.     for (Field fx : f) {
  14.       try {
  15.         System.out.println(fx.get(mc));
  16.       } catch (IllegalArgumentException ex) {
  17.         Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
  18.       } catch (IllegalAccessException ex) {
  19.         Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
  20.       }
  21.     }
  22.   }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment