KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > reflection > Child


1 /***************************************************************************************************
2  * Copyright (c) Jonas BonŽr, Alexandre Vasseur. All rights reserved. *
3  * http://aspectwerkz.codehaus.org *
4  * ---------------------------------------------------------------------------------- * The software
5  * in this package is published under the terms of the LGPL license * a copy of which has been
6  * included with this distribution in the license.txt file. *
7  **************************************************************************************************/

8 package test.reflection;
9
10 import java.lang.reflect.Method JavaDoc;
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 JavaDoc m = this.getClass().getMethod(
34                     "incr", new Class JavaDoc[]{
35                         int.class
36                     }
37             );
38             Integer JavaDoc res = (Integer JavaDoc) m.invoke(
39                     this, new Object JavaDoc[]{
40                         new Integer JavaDoc(value)
41                     }
42             );
43             return res.intValue();
44         } catch (Throwable JavaDoc t) {
45             return -1000;
46         }
47     }
48 }
Popular Tags