1 import java.lang.reflect.Method; 2 3 // Test return values of Method.invoke. 4 public class InvokeReturn { bTrue()5 public boolean bTrue() { 6 return true; 7 } 8 bFalse()9 public boolean bFalse() { 10 return false; 11 } 12 cc()13 public char cc() { 14 return 'c'; 15 } 16 s5()17 public short s5() { 18 return (short)5; 19 } 20 i6()21 public int i6() { 22 return 6; 23 } 24 l7()25 public long l7() { 26 return (long)7; 27 } 28 f8()29 public float f8() { 30 return (float)8.0; 31 } 32 d9()33 public double d9() { 34 return 9.0; 35 } 36 main(String[] args)37 public static void main(String[] args) { 38 try { 39 Object o = new InvokeReturn(); 40 Method m; 41 42 // test boolean result 43 m = o.getClass().getDeclaredMethod("bTrue", new Class[0]); 44 System.out.println(m.invoke(o, new Object[0])); 45 46 m = o.getClass().getDeclaredMethod("bFalse", new Class[0]); 47 System.out.println(m.invoke(o, new Object[0])); 48 49 // test char result 50 m = o.getClass().getDeclaredMethod("cc", new Class[0]); 51 System.out.println(m.invoke(o, new Object[0])); 52 53 // test short result 54 m = o.getClass().getDeclaredMethod("s5", new Class[0]); 55 System.out.println(m.invoke(o, new Object[0])); 56 57 // test int result 58 m = o.getClass().getDeclaredMethod("i6", new Class[0]); 59 System.out.println(m.invoke(o, new Object[0])); 60 61 // test long result 62 m = o.getClass().getDeclaredMethod("l7", new Class[0]); 63 System.out.println(m.invoke(o, new Object[0])); 64 65 // test float result 66 m = o.getClass().getDeclaredMethod("f8", new Class[0]); 67 System.out.println(m.invoke(o, new Object[0])); 68 69 // test double result 70 m = o.getClass().getDeclaredMethod("d9", new Class[0]); 71 System.out.println(m.invoke(o, new Object[0])); 72 } catch (UnsupportedOperationException e) { 73 // We get this on targets which don't support reflection (no 74 // libffi port yet). We might as well fake PASSes. 75 System.out.println("true\nfalse\nc\n5\n6\n7\n8.0\n9.0"); 76 } catch (Throwable t) { 77 t.printStackTrace(); 78 } 79 } 80 } 81