标签:
package vmrun; import java.io.InputStream; public class ClassLoadTest { public static void main(String [] args) throws Exception{ ClassLoader myLoader = new ClassLoader() { @Override public Class<?> loadClass(String name) throws ClassNotFoundException { try { String filename = name.substring(name.lastIndexOf(".")+1)+".class"; InputStream is = getClass().getResourceAsStream(filename) ; if (is== null){ return super.loadClass(name) ; } byte [] b= new byte[is.available()]; is.read(b) ; return defineClass(name, b, 0,b.length); } catch (Exception e) { throw new ClassNotFoundException(name); } } }; Object object= myLoader.loadClass("vmrun.InvokeDynamicTest").newInstance(); System.out.println(object.getClass()) ; System.out.println(object instanceof vmrun.InvokeDynamicTest); } }
输出
class vmrun.InvokeDynamicTest
false
标签:
原文地址:http://www.cnblogs.com/chuiyuan/p/4781538.html