classLoader (一)

不說廢話,上代碼吧。java

隨便寫一個類,他是由appclassLoader加載的app

package classLoaderExample;

class Bean
{
    public  void test()
    {
        System.out.println("hello");
    }
    
}

 

package classLoaderExample;


public class Main {
    

    public static void main(String[] args)  {
        System.out.println(System.getProperty("java.class.path"));
        Class typeLoaded = null;
        try {
            typeLoaded = Class.forName("classLoaderExample.Bean");//加載這個類,返回類的實例
        } catch (ClassNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        //typeLoaded.getClassLoader();
        System.out.println(typeLoaded.getClass());
        //打印該類的類加載器
        ClassLoader cl=typeLoaded.getClassLoader();
        System.out.println(cl);
        System.out.println(cl.getParent());
        System.out.println(cl.getParent().getParent());

    }

}
相關文章
相關標籤/搜索