ClassLoader

总有一些问题 来个错误模式吧

public class TestLoader extends Object {
   public static void main(String[] args)
   {
         ClassLoader myLoader = new MyClassLoader(".");
         try {
            Class loadMeClass = myLoader.loadClass("LoadMe");
            Class[] classes = loadMeClass.getInterfaces();
            for (int i=0; i<classes.length; i++) {
                System.out.println("Interfaces:" + classes[i].getName());
            }
            Object o = loadMeClass.newInstance();
            //这是不能随意Cast的.
            Stuff loadMe = (Stuff)o;

         } catch (Exception oops) {
            oops.printStackTrace();
         }
   }
}

你可能感兴趣的:(ClassLoader)