Introduction to OOP | Chapter 25: Reflection and Introspection : | next | previous | audio | real | text |
class SimpleClassLoader extends ClassLoader { public Class getClass (String name) { Class theClass = null; try { File f = new File(name); InputStream is = new FileInputStream(f); int bufsize = (int) f.length(); byte buf [] = new byte[bufsize]; is.read(buf, 0, bufsize); is.close(); theClass = defineClass (null, buf, 0, buf.length); } catch (Exception e) { System.err.println("Error during load " + e); System.exit(1); } return theClass; } }Once you have a class, you can create instances, or execute methods.