Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class MyClass {
- int x = 5;
- static double d = 43.2;
- }
- public class Test {
- public static void main(String[] args) {
- MyClass mc = new MyClass();
- Class c = mc.getClass();
- Field[] f = c.getDeclaredFields();
- for (Field fx : f) {
- try {
- System.out.println(fx.get(mc));
- } catch (IllegalArgumentException ex) {
- Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment