Test ClassLoader

来源:互联网 发布:免费手机图文编辑软件 编辑:程序博客网 时间:2024/06/03 15:52
package com.fangjian;public class Test1 implements ITest {public Test1(){};@Overridepublic String hello() {return "hello";}/** * @param args */public static void main(String[] args) {Test1 t1=new Test1();System.out.println(t1.hello());System.out.println(String.class.getClassLoader());System.out.println(Test1.class.getClassLoader());try {Class T1Clazz=ClassLoader.getSystemClassLoader().loadClass("com.fangjian.Test1");ITest t2=(ITest)T1Clazz.newInstance();System.out.println("t2:"+t2.hello());} catch (ClassNotFoundException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (InstantiationException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IllegalAccessException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}

output:

hello
null
sun.misc.Launcher$AppClassLoader@546b97fd
t2:hello