public static void main(String[] args) { Class c = null; try { c = Class.forName("Test.FancyToy"); } catch (ClassNotFoundException e) { print("Can't find FancyToy"); System.exit(1); } printInfo(c); for (Class face : c.getInterfaces()) printInfo(face); Class up = c.getSuperclass(); Object obj = null; try { obj = up.newInstance(); } catch (InstantiationException e) { print("Cannot instantiate"); System.exit(1); } catch (IllegalAccessException e) { print("Cannot access"); System.exit(1); } printInfo(obj.getClass()); }
static void printInfo(Class cc) { print("Classname: " + cc.getName() + " is interface? [" + cc.isInterface() + "]"); print("Simple name: " + cc.getSimpleName()); print("Canonical name: " + cc.getCanonicalName()); }