1 package gov.nasa.jpf.jvm; 20 21 24 public class TestCast { 25 public static void main (String [] args) { 26 TestCast t = new TestCast(); 27 28 if (args.length > 0) { 29 for (int i = 0; i < args.length; i++) { 31 String func = args[i]; 32 33 if ("testCast".equals(func)) { 36 t.testCast(); 37 } else if ("testCastFail".equals(func)) { 38 t.testCastFail(); 39 } else { 40 throw new IllegalArgumentException ("unknown test function"); 41 } 42 } 43 } else { 44 t.testCast(); 46 t.testCastFail(); 47 } 48 } 49 50 public void testCast () { 51 B b = new B(); 52 A a = b; 53 54 I i = (I) a; 55 K k = (K) b; 56 } 57 58 public void testCastFail () { 59 A a = new A(); 60 61 try { 62 I i = (I) a; 63 } catch (ClassCastException ccx) { 64 return; 65 } 66 67 throw new RuntimeException ("illegal cast passed"); 68 } 69 70 static interface I { 71 } 72 73 static interface J extends I { 74 } 75 76 static interface K { 77 } 78 79 static class A implements K { 80 } 81 82 static class B extends A implements J { 83 } 84 } | Popular Tags |