2
|
1 |
/*
|
|
2 |
* Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 |
* have any questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
import java.lang.reflect.*;
|
|
25 |
|
|
26 |
/*
|
|
27 |
* Debuggee which exercises various types method calls
|
|
28 |
*/
|
|
29 |
|
|
30 |
class MethodCalls {
|
|
31 |
|
|
32 |
public static void main(String args[]) throws Exception {
|
|
33 |
(new MethodCalls()).go();
|
|
34 |
}
|
|
35 |
|
|
36 |
static void staticCaller(MethodCalls mc) throws Exception {
|
|
37 |
System.out.println("Called staticCaller");
|
|
38 |
staticCallee();
|
|
39 |
mc.instanceCallee();
|
|
40 |
|
|
41 |
/*
|
|
42 |
* Invocation by reflection. This also exercises native method calls
|
|
43 |
* since Method.invoke is a native method.
|
|
44 |
*/
|
|
45 |
Method m = MethodCalls.class.getDeclaredMethod("staticCallee", new Class[0]);
|
|
46 |
m.invoke(mc, new Object[0]);
|
|
47 |
}
|
|
48 |
|
|
49 |
void instanceCaller() throws Exception {
|
|
50 |
System.out.println("Called instanceCaller");
|
|
51 |
staticCallee();
|
|
52 |
instanceCallee();
|
|
53 |
|
|
54 |
/*
|
|
55 |
* Invocation by reflection. This also exercises native method calls
|
|
56 |
* since Method.invoke is a native method.
|
|
57 |
*/
|
|
58 |
Method m = getClass().getDeclaredMethod("instanceCallee", new Class[0]);
|
|
59 |
m.invoke(this, new Object[0]);
|
|
60 |
}
|
|
61 |
|
|
62 |
static void staticCallee() {
|
|
63 |
System.out.println("Called staticCallee");
|
|
64 |
}
|
|
65 |
|
|
66 |
void instanceCallee() {
|
|
67 |
System.out.println("Called instanceCallee");
|
|
68 |
}
|
|
69 |
|
|
70 |
void go() throws Exception {
|
|
71 |
instanceCaller();
|
|
72 |
staticCaller(this);
|
|
73 |
}
|
|
74 |
}
|