深入JVM之根類載入器的測試

來源:互聯網
上載者:User
package com.jadyer.classloader;/** * 深入JVM之根類載入器的測試 * @author 宏宇 * @editor Jan 24, 2012 11:23:22 PM * @see ================================================================================= * @see java.lang.Class.getClassLoader()方法的API中,有如下說明 * @see This method will return null in such implementations * @see if this class was loaded by the bootstrap class loader * @see 也就是說,如果這個類是由根類載入器載入的,那麼該方法將返回null * @see ================================================================================= * @see 我們程式中最後列印出來的null,就說明String類是由根類載入器載入的 * @see 而列印出來的sun.misc.Launcher$AppClassLoader@addbf1字串 * @see 就說明我們自訂的TestBB類是由應用載入器載入的(App即Application) * @see ================================================================================= */public class BootstrapTest {public static void main(String[] args)throws Exception{Class clazz = Class.forName("java.lang.String");System.out.println("String類的類載入器為: " + clazz.getClassLoader());Class clazz22 = Class.forName("com.jadyer.classloader.TestEmpty"); //注意:寫全名System.out.println("TestEmpty類載入器為: " + clazz22.getClassLoader());}}/** * 定義了一個空類 */class TestEmpty{}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.