immutable class Imm { int x; } template public class foo { T x; } public class O1 { int x; public O1() { x = 1; } } public class O2 extends O1 { private O2() {} public O2(int x) {} } public class O3 extends O2 { int y; public O3() { super(4); y = 2; } } public class O4 extends O3 { public O4(int x) {} } public class O5 { } public class O6 extends O5 { } public class O7 { int x; } public class testClass { public static void info(Object o) { info(o.getClass(),"",true,false); } public static void info(Class cls, String indent, boolean newInstgood, boolean suppressInst) { Class supercls = cls.getSuperclass(); Class[] inf = cls.getInterfaces(); System.out.println(indent+"Class name: " + cls.getName()); System.out.println(indent+"isInterface(): " + cls.isInterface()); if (cls.creator() != 0) System.out.println("ERROR Class object should be on P0!"); /* forName test */ if (cls != void.class && cls != boolean.class && cls != byte.class && cls != short.class && cls != int.class && cls != long.class && cls != float.class && cls != double.class && cls != char.class ) { /* forName doesn't work for primitives */ Class test = null; try { test = cls.forName(cls.getName()); } catch (ClassNotFoundException exn) { System.out.println("ERROR in Class.forName(): " + exn); } if (test != cls) System.out.println("ERROR Class.forName() lookup failed"); try { cls.forName("poop"); System.out.println("ERROR Class.forName() worked when it should have failed!"); } catch (ClassNotFoundException exn) { } try { cls.forName("int"); System.out.println("ERROR Class.forName() worked when it should have failed!"); } catch (ClassNotFoundException exn) { } } /* instantiation test */ if (!suppressInst) { try { Object o = cls.newInstance(); if (!newInstgood) System.out.println(indent+"ERROR newInstance() worked when it should have failed!!!"); if (!o.isLocal()) System.out.println(indent+"ERROR newInstance() isLocal incorrect"); if (o.getClass() != cls) System.out.println(indent+"ERROR newInstance() class not equal"); if (o == o.getClass().newInstance()) System.out.println(indent+"ERROR newInstance() returned duplicate object"); } catch (InstantiationException x) { if (newInstgood) System.out.println(indent+"ERROR newInstance() failed:" + x); } catch (ExceptionInInitializerError x) { System.out.println(indent+"ERROR got an exn in newInstance():" + x + " : " + x.getCause()); } catch (Throwable exn) { System.out.println(indent+"ERROR got an unexpected errors: " + exn); } } /* hierarchy info */ if (supercls != null) { System.out.println(indent+"extends:"); info(supercls,indent + " ", newInstgood,true); } if (inf.length > 0) { System.out.println(indent+"implements:"); for (int i=0; i < inf.length; i++) { info(inf[i],indent + " ", false, true); } } } public static void info(Class cls, boolean newInstgood) { info(cls, "", newInstgood, false); } public static void main(String[]args) { String s = "hi"; Object o = new Object(); Class strcls = s.getClass(); Class objcls = o.getClass(); System.out.println(objcls); //System.out.println(o); System.out.println(strcls.getSuperclass() == objcls); System.out.println(strcls.getClassLoader()); try { info(new String()); info(objcls.getClass(),false); info(new ArrayIndexOutOfBoundsException()); info(new ti.io.BulkRandomAccessFile("/dev/null","r").getClass(),false); info(new InstantiationError()); System.out.println("Testing class literals.."); info(Object.class,true); info(ArrayIndexOutOfBoundsException.class,true); info(Imm.class,false); info(RectDomain<2>.class,false); info(int.class,false); info(Integer.TYPE,false); info(Integer.class,false); info(void.class,false); info(Void.TYPE,false); info(Void.class,true); info(template foo.class,true); info(O1.class,true); info(O2.class,false); info(O3.class,true); info(O4.class,false); info(O5.class,true); info(O6.class,true); info(O6.class,true); try { O1 o1 = (O1)O1.class.newInstance(); O3 o3 = (O3)O3.class.newInstance(); assert o1.x == 1 : "bad x"; assert o3.y == 2 : "bad y"; } catch (Throwable exn) { System.out.println("ERROR: " + exn); } throw new java.io.EOFException("hello"); } catch (Throwable exn) { System.out.println(exn); } //throw new NullPointerException("yo mama"); } }