1 /* Test interface dispatch, type checking (instanceof), and casting. */
8 interface IB extends IA
13 interface IC extends IB
34 class CB implements IB
55 class CD extends CC implements IC
64 System.out.println("CD c()");
81 class CE extends CB implements IB, ID
100 public class InterfaceDispatch
102 public static void main(String args[])
104 new InterfaceDispatch();
107 public InterfaceDispatch()
111 /* Object instanceof CLASS */
112 Object obj = new CA();
114 if (obj instanceof CA)
116 System.out.println ("ok 1");
120 System.out.println ("FAIL 1");
125 if (!(obj instanceof CA))
127 System.out.println ("ok 2a");
131 System.out.println ("FAIL 2a");
134 if (obj instanceof CB)
136 System.out.println ("ok 2b");
140 System.out.println ("FAIL 2b");
144 /* Object instanceof INTERFACE */
147 if (!(obj instanceof IC))
149 System.out.println("ok 3");
153 System.out.println ("FAIL 3");
156 if (obj instanceof IB)
158 System.out.println("ok 4");
162 System.out.println ("FAIL 4");
165 /* InterfaceRef instanceof INTERFACE */
169 if (ia instanceof IB)
171 System.out.println("ok 5");
175 System.out.println ("FAIL 5");
179 if (!(ia instanceof IC))
181 System.out.println("ok 6");
185 System.out.println ("FAIL 6");
188 /* InterfaceRef instanceof CLASS */
190 if (ia instanceof CB)
192 System.out.println("ok 7");
196 System.out.println ("FAIL 7");
200 if (!(ia instanceof CD))
202 System.out.println("ok 8");
206 System.out.println ("FAIL 8");
211 Object obj_ca = new CA();
212 Object obj_cc = new CC();
219 System.out.println("ok 9");
221 catch (ClassCastException x)
223 System.out.println("FAIL 9");
231 System.out.println("FAIL 10");
233 catch (ClassCastException x)
235 System.out.println("ok 10");
243 System.out.println("FAIL 11");
245 catch (ClassCastException x)
247 System.out.println("ok 11");
250 /* _Jv_LookupInterfaceMethod */
251 Object obj_cb = new CB();
255 if (ib.a().equalsIgnoreCase("CB a()"))
256 System.out.println("ok 12");
258 System.out.println("FAIL 12");
261 if (ic.a().equalsIgnoreCase("CD a()"))
262 System.out.println("ok 13");
264 System.out.println("FAIL 13");
267 System.out.println("ok 14");
269 System.out.println("FAIL 14");
271 Object ce = new CE();
276 if (ib.b().equals("CE b()") && id.a().equals("CE a()"))
277 System.out.println("ok 15");
279 System.out.println("FAIL 15");
281 String t = ((ID)ce).z();
283 if (t.equalsIgnoreCase("CE z()"))
284 System.out.println("ok 16");
286 System.out.println("FAIL 16");
290 Object[] obj_a = new CC[10];
293 CB[] ca_a = (CB[]) obj_a;
294 System.out.println("ok 17");
296 catch (ClassCastException x)
298 System.out.println("FAIL 17");
301 if (obj_a instanceof IB[])
303 System.out.println("ok 18");
307 System.out.println("FAIL 18");
310 IB[] ib_a = new CD[5];
313 CD[] cd_a = (CD[]) ib_a;
314 System.out.println("ok 19");
316 catch (ClassCastException x)
318 System.out.println("FAIL 19");
326 System.out.println("FAIL 20");
328 catch (ClassCastException x)
330 System.out.println("ok 20");
334 /* Primitive types */
336 short[] short_a = new short[100];
341 System.out.println("ok 21");
343 catch (ClassCastException x)
345 System.out.println("FAIL 21");
350 short[] short_b = (short[]) obj;
351 System.out.println("ok 22");
353 catch (ClassCastException x)
355 System.out.println("FAIL 22");
362 short_b = (int[]) obj;
363 System.out.println("FAIL 23");
365 catch (ClassCastException x)
367 System.out.println("ok 23");
370 Object obj1 = new int[25];
372 if (obj1 instanceof short[])
374 System.out.println("FAIL 24");
378 System.out.println("ok 24");
381 if (obj1 instanceof int[])
383 System.out.println("ok 25");
387 System.out.println("FAIL 25");
390 /* null assignment */
394 if (obj_ca2 instanceof CA)
396 System.out.println("FAIL 26");
400 System.out.println("ok 26");