|
| 1 | +package test; |
| 2 | + |
| 3 | +import java.util.AbstractMap; |
| 4 | +import java.util.HashMap; |
| 5 | + |
| 6 | +class A { |
| 7 | + private void init() { |
| 8 | + System.out.println("class A init"); |
| 9 | + } |
| 10 | + |
| 11 | + protected void init(String a) { |
| 12 | + System.out.println("class A init String a"); |
| 13 | + } |
| 14 | + |
| 15 | + protected void init2() { |
| 16 | + System.out.println("class A init2"); |
| 17 | + init(); |
| 18 | + } |
| 19 | +} |
| 20 | + |
| 21 | +class B extends A { |
| 22 | + protected void init() { |
| 23 | + System.out.println("class B init"); |
| 24 | + super.init2(); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + protected void init(String b) { |
| 29 | + System.out.println("class B init String b"); |
| 30 | + } |
| 31 | + |
| 32 | +} |
| 33 | + |
| 34 | +@SuppressWarnings({ "serial", "rawtypes" }) |
| 35 | +public class Test_Bugs extends HashMap { |
| 36 | + |
| 37 | + private String me = "me"; |
| 38 | + |
| 39 | + public Test_Bugs() { |
| 40 | + System.out.println("this is Test_Bugs()" + me); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + public Test_Bugs(String s) { |
| 45 | + System.out.println("this is Test_Bugs(String):" + s + me); |
| 46 | + } |
| 47 | + |
| 48 | + public Test_Bugs(Object[] o) { |
| 49 | + System.out.println("this is Test_Bugs(Object[]):" + o + me); |
| 50 | + } |
| 51 | + |
| 52 | + public Test_Bugs(String s, String t) { |
| 53 | + System.out.println("this is Test_Bugs(String,String):" + s + t + me); |
| 54 | + } |
| 55 | + |
| 56 | + private void test(AbstractMap a) { |
| 57 | + System.out.println(a + " is an AbstractMap"); |
| 58 | + } |
| 59 | + |
| 60 | + private void test(Object ja) { |
| 61 | + System.out.println(ja + " is an Object"); |
| 62 | + } |
| 63 | + |
| 64 | + private void test1(Number ja) { |
| 65 | + System.out.println(ja + " is a Number"); |
| 66 | + } |
| 67 | + |
| 68 | + private void test1(int ja) { |
| 69 | + System.out.println(ja + " is an int"); |
| 70 | + } |
| 71 | + |
| 72 | + private static String getFont(String f) { |
| 73 | + return f; |
| 74 | + } |
| 75 | + |
| 76 | + private static String getFont(String f, String y) { |
| 77 | + return f + y; |
| 78 | + } |
| 79 | + |
| 80 | + public static void main(String[] args) { |
| 81 | + |
| 82 | + new B().init(); |
| 83 | + |
| 84 | + // report should be: |
| 85 | + // |
| 86 | + // class B init |
| 87 | + // class A init2 |
| 88 | + // class A init |
| 89 | + |
| 90 | + try { |
| 91 | + Class<?> cl; |
| 92 | + cl = Class.forName("test.Test_Bugs"); |
| 93 | + cl.getConstructor(String.class, String.class).newInstance( |
| 94 | + new Object[] { "test1", "test2" }); |
| 95 | + cl.getConstructor(Object[].class).newInstance( |
| 96 | + new Object[] { new Object[] { "test1", "test2" } }); |
| 97 | + cl.getConstructor(String.class, String.class).newInstance("test1", |
| 98 | + "test2"); |
| 99 | + cl.getConstructor().newInstance(); |
| 100 | + cl.newInstance(); |
| 101 | + } catch (Exception e) { |
| 102 | + // TODO Auto-generated catch block |
| 103 | + e.printStackTrace(); |
| 104 | + } |
| 105 | + |
| 106 | + System.out.println(getFont("f")); |
| 107 | + System.out.println(getFont("f", "y")); |
| 108 | + |
| 109 | + Test_Bugs t = new Test_Bugs(); |
| 110 | + |
| 111 | + t.test1(Integer.valueOf(33)); |
| 112 | + t.test1(33); |
| 113 | + |
| 114 | + t.test(t); |
| 115 | + t.test((Object) t); |
| 116 | + |
| 117 | + printit(2, 3, 4, 5); |
| 118 | + System.out.println(args); |
| 119 | + |
| 120 | + char[] test = new char[] { '1', '2', '3', '4', '5' }; |
| 121 | + String s = new String(test, 2, 3); |
| 122 | + |
| 123 | + System.out.println("char test: 345 = " + s); |
| 124 | + |
| 125 | + main2(null); |
| 126 | + |
| 127 | + } |
| 128 | + |
| 129 | + static void printit(int... t) { |
| 130 | + for (int i = 0; i < t.length; i++) |
| 131 | + System.out.println(t[i]); |
| 132 | + } |
| 133 | + |
| 134 | + // ///////// https://groups.google.com/forum/#!topic/java2script/mjrUxnp1VS8 |
| 135 | + |
| 136 | + public interface INTERFACE { |
| 137 | + } |
| 138 | + |
| 139 | + public static class CLASS { |
| 140 | + } |
| 141 | + |
| 142 | + public static class Baz extends CLASS implements INTERFACE { |
| 143 | + } |
| 144 | + |
| 145 | + public static class Qux { |
| 146 | + |
| 147 | + void f(INTERFACE arg) { |
| 148 | + System.out.println("f(INTERFACE) called -- CORRECT"); |
| 149 | + } |
| 150 | + |
| 151 | + void f(CLASS arg) { |
| 152 | + |
| 153 | + System.out.println("f(CLASS) called -- ERROR"); |
| 154 | + } |
| 155 | + |
| 156 | + } |
| 157 | + |
| 158 | + public static void g(INTERFACE foo) { |
| 159 | + |
| 160 | + Qux q = new Qux(); |
| 161 | + |
| 162 | + q.f(foo); |
| 163 | + |
| 164 | + } |
| 165 | + |
| 166 | + public static void main2(String[] args) { |
| 167 | + |
| 168 | + Baz b = new Baz(); |
| 169 | + |
| 170 | + g(b); |
| 171 | + |
| 172 | + } |
| 173 | + |
| 174 | + // ///////// https://groups.google.com/forum/#!topic/java2script/9FMWuEiH9Ik |
| 175 | + |
| 176 | + public class SubBaseClass { |
| 177 | + |
| 178 | + } |
| 179 | + public class BaseClass { |
| 180 | + |
| 181 | + public BaseClass() { |
| 182 | + this(""); |
| 183 | + } |
| 184 | + |
| 185 | + public BaseClass(String prefix) { |
| 186 | + System.out.println(prefix + "Hello from BaseClass"); |
| 187 | + } |
| 188 | + |
| 189 | + } |
| 190 | + |
| 191 | + public class SubClass extends BaseClass { |
| 192 | + |
| 193 | + SubClass(String message) { |
| 194 | + super(); |
| 195 | + System.out.println(message); |
| 196 | + } |
| 197 | + |
| 198 | + } |
| 199 | + |
| 200 | + public void main3(String[] args) { |
| 201 | + /** |
| 202 | + * @j2sNative |
| 203 | + * |
| 204 | + * debugger; |
| 205 | + */ |
| 206 | + {} |
| 207 | + new SubClass("Hello from SubClass"); |
| 208 | + System.out.println("Done."); |
| 209 | + } |
| 210 | + |
| 211 | +} |
| 212 | + |
0 commit comments