@@ -0,0 +1,1103 @@
+package amery.jdk.basic;%0A%0Aimport java.io.IOException;%0Aimport java.io.InputStream;%0A%0A/**%0A * Created by ahan on 13/07/2017.%0A */%0Apublic class MyClassLoaderTest %7B%0A%0A%09/**%0A%09 * http://www.jianshu.com/p/b09888ddac35%0A%09 * @param args%0A%09 * @throws Exception%0A%09 */%0A%09public static void main(String%5B%5D args) throws Exception %7B%0A%0A%09%09ClassLoader myLoader = new ClassLoader() %7B%0A%09%09%09@Override%0A%09%09%09public Class%3C?%3E loadClass(String name) throws ClassNotFoundException %7B%0A%09%09%09%09try %7B%0A%09%09%09%09%09String fileName=name.substring(name.lastIndexOf(%22.%22)+1)+%22.class%22;%0A%09%09%09%09%09InputStream is=getClass().getResourceAsStream(fileName);%0A%09%09%09%09%09if( is == null )%7B%0A%09%09%09%09%09%09return super.loadClass(name);%0A%09%09%09%09%09%7D%0A%09%09%09%09%09byte%5B%5D bytes = new byte%5Bis.available()%5D;%0A%09%09%09%09%09is.read(bytes); //%E9%80%9A%E8%BF%87%E8%87%AA%E5%AE%9A%E4%B9%89%E7%B1%BB%E5%8A%A0%E8%BD%BD%E5%99%A8%E8%AF%BB%E5%8F%96class%E6%96%87%E4%BB%B6%E7%9A%84%E4%BA%8C%E8%BF%9B%E5%88%B6%E6%B5%81%0A%09%09%09%09%09return defineClass(name, bytes, 0,bytes.length);%0A%0A%09%09%09%09%7D catch (IOException e) %7B%0A%09%09%09%09%09e.printStackTrace();%0A%09%09%09%09%09throw new ClassNotFoundException(name);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D;%0A%0A%0A%09%09Object obj = myLoader.loadClass(%22amery.jdk.basic.MyClassLoaderTest%22).newInstance();%0A%09%09System.out.println(obj.getClass() );%0A%09%09System.out.println(obj instanceof MyClassLoaderTest);%0A%09%7D%0A%7D%0A

add classloader