1 import java.lang.reflect.*;
3 public class ReflectEx {
5 throw new ClassCastException();
10 public static void main(String [] args) {
12 ReflectEx o=new ReflectEx();
13 System.out.println("Test 1 failed (should have gotten exception)");
14 } catch (Exception e) {
15 if (! (e instanceof ClassCastException)) {
16 System.out.println("Test 1 failed (wrong exception)");
18 System.out.println("Test 1 OK");
24 Class c= Class.forName("ReflectEx");
25 Constructor con=c.getConstructors()[0];
27 Object o=con.newInstance(new Object[0]);
28 System.out.println("Test 2 failed (should have gotten exception)");
29 } catch (Exception e) {
30 if (! (e instanceof InvocationTargetException)) {
31 System.out.println("Test 2 failed (wrong exception)");
33 System.out.println("Test 2 OK");
38 System.out.println("End of test");