|
4 | 4 |
|
5 | 5 | class Test_Static extends Test_ implements Test_int3, Test_int2, Test_int1 { |
6 | 6 |
|
7 | | - /** |
8 | | - * Note that a static block in a main class is executed prior to running main(). |
9 | | - * So you can set the arguments here as thisApplet.__Info.args, for example. |
10 | | - * Setting j2sHeadless = true prevents all the AWT/Swing classes from being loaded |
11 | | - * but also means you cannot use them later. It really means headless just like in Java |
12 | | - * |
13 | | - * @j2sNative |
14 | | - * |
15 | | - * j2sHeadless = true; |
16 | | - * |
17 | | - * thisApplet.__Info.args = ["1","2","3"]; |
18 | | - * |
19 | | - */ |
20 | | - static { |
21 | | - // JS only |
22 | | - } |
23 | | - |
24 | | - private static byte[] bytearray = {1,2,127}; |
| 7 | +// /** |
| 8 | +// * Note that a static block in a main class is executed prior to running main(). |
| 9 | +// * So you can set the arguments here as thisApplet.__Info.args, for example. |
| 10 | +// * Setting j2sHeadless = true prevents all the AWT/Swing classes from being loaded |
| 11 | +// * but also means you cannot use them later. It really means headless just like in Java |
| 12 | +// * |
| 13 | +// * @j2sNative |
| 14 | +// * |
| 15 | +// * j2sHeadless = true; |
| 16 | +// * |
| 17 | +// * thisApplet.__Info.args = ["1","2","3"]; |
| 18 | +// * |
| 19 | +// */ |
| 20 | +// static { |
| 21 | +// // JS only |
| 22 | +// } |
25 | 23 |
|
26 | | - private final static Integer iI = 11; |
27 | | - private final static Integer iI1 = new Integer(13); |
28 | | - private final static Float fF2 = 12f; |
29 | | - private final static Float fF1 = new Float(12); |
30 | | - |
31 | | - private final static String st = "testing"; |
32 | | - static { |
33 | | - assert (iI == 11); |
34 | | - } |
35 | | - private static String st1 = st; |
36 | | - private static boolean b = false; |
37 | | - private static int y; |
38 | | - private static char c = 'c'; |
39 | | - private static int innerI = Test_Class_Inner.i; |
40 | | - static { |
41 | | - System.out.println(Test_int1.int1); |
42 | | - System.out.println(Test_int2.int2); |
43 | | - System.out.println(Test_int3.int3); |
44 | | - |
45 | | - System.out.println(innerI); |
46 | | - assert(innerI == 5); |
47 | | - int x = 3; |
48 | | - y = Test_Boolean.i_; |
49 | | - Test_Array.y = 3; |
50 | | - y = Test_Array.y; |
51 | | - y = x; |
52 | | - Test_Boolean.main(null); |
53 | | - t = "setFromStaticInitializer"; |
54 | | - s = "setFromStaticInitializer"; |
55 | | - } |
56 | | - |
57 | | - public static String s, t = null; |
58 | | - |
59 | | - private void test1() {}; |
60 | | - private void test() { |
61 | | - test1(); |
62 | | - }; |
63 | | - |
64 | | - private static byte[] bytes = new byte[3]; |
65 | | - public static byte[] getByteArray() { |
66 | | - return bytes; |
| 24 | + private static String testStatic() { |
| 25 | + return "no kidding!"; |
67 | 26 | } |
| 27 | + static Test_Static test = null; |
| 28 | + static Test_Class testc = null; |
| 29 | + |
| 30 | +// private static byte[] bytearray = {1,2,127}; |
| 31 | +// |
| 32 | +// private final static Integer iI = 11; |
| 33 | +// private final static Integer iI1 = new Integer(13); |
| 34 | +// private final static Float fF2 = 12f; |
| 35 | +// private final static Float fF1 = new Float(12); |
| 36 | +// |
| 37 | +// private final static String st = "testing"; |
| 38 | +// static { |
| 39 | +// assert (iI == 11); |
| 40 | +// } |
| 41 | +// private static String st1 = st; |
| 42 | +// private static boolean b = false; |
| 43 | +// private static int y; |
| 44 | +// private static char c = 'c'; |
| 45 | +// private static int innerI = Test_Class_Inner.i; |
| 46 | +// static { |
| 47 | +// System.out.println(Test_int1.int1); |
| 48 | +// System.out.println(Test_int2.int2); |
| 49 | +// System.out.println(Test_int3.int3); |
| 50 | +// |
| 51 | +// System.out.println(innerI); |
| 52 | +// assert(innerI == 5); |
| 53 | +// int x = 3; |
| 54 | +// y = Test_Boolean.i_; |
| 55 | +// Test_Array.y = 3; |
| 56 | +// y = Test_Array.y; |
| 57 | +// y = x; |
| 58 | +// Test_Boolean.main(null); |
| 59 | +// t = "setFromStaticInitializer"; |
| 60 | +// s = "setFromStaticInitializer"; |
| 61 | +// } |
| 62 | +// |
| 63 | +// public static String s, t = null; |
| 64 | +// |
| 65 | +// private void test1() {}; |
| 66 | +// private void test() { |
| 67 | +// test1(); |
| 68 | +// }; |
| 69 | +// |
| 70 | +// private static byte[] bytes = new byte[3]; |
| 71 | +// public static byte[] getByteArray() { |
| 72 | +// return bytes; |
| 73 | +// } |
68 | 74 |
|
69 | 75 | @SuppressWarnings("static-access") |
70 | 76 | public static void main(String[] args) { |
71 | 77 |
|
72 | | - assert(t == null); |
73 | | - assert s == "setFromStaticInitializer"; |
74 | | - |
75 | | - |
76 | | - /** |
77 | | - * @j2sNative |
78 | | - * |
79 | | - * System.out.println(args); |
80 | | - * |
81 | | - * try{ |
82 | | - * afldsjadf.adfadf; |
83 | | - * |
84 | | - * } catch(e) {// is being called by Test_.js |
85 | | - * if (e.stack.indexOf("Test_.js")) args[1] = 2; |
86 | | - * } |
87 | | - * |
88 | | - */ |
89 | | - { |
90 | | - args = new String[] {"1","2","3"}; |
91 | | - } |
92 | | - assert(args[1] == "2"); |
93 | | - |
94 | | - assert (y == 3); |
95 | | - b = false; |
96 | | - new Test_Static().test(); |
97 | | - new Test_Static().b ^= true; |
98 | | - System.out.println(bytearray[2]); |
99 | | - |
100 | | - new Test_Static().bytearray[--y]++; |
101 | | - |
102 | | - |
103 | | - System.out.println(bytearray[2]); |
104 | | - assert(bytearray[2] == -128); |
| 78 | + new Test_Static().callStatic(); |
| 79 | + // each of these pairs will be the same: |
| 80 | + test.testStatic(); |
| 81 | + Test_Static.testStatic(); |
| 82 | + // and |
| 83 | + testc.testStatic(); |
| 84 | + Test_Class.testStatic(); |
105 | 85 |
|
106 | | - int p = 0; |
107 | | - getByteArray()[p++] += (byte) ++p; |
108 | | - System.out.println((new Test_Static()).getByteArray()[2]++); |
109 | | - System.out.println((new Test_Static()).getByteArray()[2]); |
110 | 86 |
|
111 | | - byte bb = 127; |
112 | | - bb++; |
113 | | - System.out.println("bb = " + bb); |
114 | | - assert(bb == -128); |
115 | | - y++; |
116 | | - new Test_Static().y++; |
117 | | - new Test_Static().s += "test1" + c++ + 3 + 5.5f + c + 5.5 + y; |
118 | | - assert (s.equals("setFromStaticInitializertest1c35.5d5.54") && b == true); |
119 | | - |
120 | | - int i = 3 + y + (new Test_Static().y++); |
121 | | - |
122 | | - assert (i == 11 && y == 5); |
123 | | - i += 3 + y + ++(new Test_Static().y); |
124 | | - assert (y == 6 && i == 25); |
125 | | - |
126 | | - Test_Static st = new Test_Static(); |
127 | | - st.y++; |
128 | | - |
129 | | - new Test_Static().y--; |
130 | | - y--; |
| 87 | + String s = test.testStatic(); |
| 88 | + System.out.println(s); |
| 89 | + System.out.println(test.testStatic()); |
| 90 | + |
| 91 | +// assert(t == null); |
| 92 | +// assert s == "setFromStaticInitializer"; |
| 93 | +// |
| 94 | +// |
| 95 | +// /** |
| 96 | +// * @j2sNative |
| 97 | +// * |
| 98 | +// * System.out.println(args); |
| 99 | +// * |
| 100 | +// * try{ |
| 101 | +// * afldsjadf.adfadf; |
| 102 | +// * |
| 103 | +// * } catch(e) {// is being called by Test_.js |
| 104 | +// * if (e.stack.indexOf("Test_.js")) args[1] = 2; |
| 105 | +// * } |
| 106 | +// * |
| 107 | +// */ |
| 108 | +// { |
| 109 | +// args = new String[] {"1","2","3"}; |
| 110 | +// } |
| 111 | +// assert(args[1] == "2"); |
| 112 | +// |
| 113 | +// assert (y == 3); |
| 114 | +// b = false; |
| 115 | +// new Test_Static().test(); |
| 116 | +// new Test_Static().b ^= true; |
| 117 | +// System.out.println(bytearray[2]); |
| 118 | +// |
| 119 | +// new Test_Static().bytearray[--y]++; |
| 120 | +// |
| 121 | +// |
| 122 | +// System.out.println(bytearray[2]); |
| 123 | +// assert(bytearray[2] == -128); |
| 124 | +// |
| 125 | +// int p = 0; |
| 126 | +// getByteArray()[p++] += (byte) ++p; |
| 127 | +// System.out.println((new Test_Static()).getByteArray()[2]++); |
| 128 | +// System.out.println((new Test_Static()).getByteArray()[2]); |
| 129 | +// |
| 130 | +// byte bb = 127; |
| 131 | +// bb++; |
| 132 | +// System.out.println("bb = " + bb); |
| 133 | +// assert(bb == -128); |
| 134 | +// y++; |
| 135 | +// new Test_Static().y++; |
| 136 | +// new Test_Static().s += "test1" + c++ + 3 + 5.5f + c + 5.5 + y; |
| 137 | +// assert (s.equals("setFromStaticInitializertest1c35.5d5.54") && b == true); |
| 138 | +// |
| 139 | +// int i = 3 + y + (new Test_Static().y++); |
| 140 | +// |
| 141 | +// assert (i == 11 && y == 5); |
| 142 | +// i += 3 + y + ++(new Test_Static().y); |
| 143 | +// assert (y == 6 && i == 25); |
| 144 | +// |
| 145 | +// Test_Static st = new Test_Static(); |
| 146 | +// st.y++; |
| 147 | +// |
| 148 | +// new Test_Static().y--; |
| 149 | +// y--; |
| 150 | +// |
| 151 | +// String y1 = "0"; |
| 152 | +// y1 += "test" + c + 3 + 5.5f + c + 5.5; |
| 153 | +// assert (y1.equals("0testd35.5d5.5")); |
| 154 | +// System.out.println("Test_Static OK"); |
| 155 | + } |
131 | 156 |
|
132 | | - String y1 = "0"; |
133 | | - y1 += "test" + c + 3 + 5.5f + c + 5.5; |
134 | | - assert (y1.equals("0testd35.5d5.5")); |
135 | | - System.out.println("Test_Static OK"); |
| 157 | + private void callStatic() { |
| 158 | + this.testStatic(); // will be C$.testStatic() |
136 | 159 | } |
137 | 160 |
|
138 | 161 | } |
|
0 commit comments