1 8 package test.reflection; 9 10 import java.lang.reflect.Method ; 11 12 public class Child extends Super { 13 public int incr(int value) { 14 int res = super.incr(value); 15 return (res >= 0) ? (res + 1) : (res - 1); 16 } 17 18 public static int incrStatic(int value) { 19 int res = Super.incrStatic(value); 20 return (res >= 0) ? (res + 1) : (res - 1); 21 } 22 23 public int do$2(int i) { 24 return i; 25 } 26 27 public int do$1(int i) { 28 return i; 29 } 30 31 public int reflectionCallIncr(int value) { 32 try { 33 Method m = this.getClass().getMethod( 34 "incr", new Class []{ 35 int.class 36 } 37 ); 38 Integer res = (Integer ) m.invoke( 39 this, new Object []{ 40 new Integer (value) 41 } 42 ); 43 return res.intValue(); 44 } catch (Throwable t) { 45 return -1000; 46 } 47 } 48 } | Popular Tags |