Home  >  Q&A  >  body text

关于java的类加载器

public class Main {
    public static void main(String[] args) {
        System.out.println(String.class.getClassLoader());
        System.out.println(Main.class.getClassLoader());
    }
}

分别输出null和AppClassLoader,为什么String是null?自己写的类即classpath下的是通过AppClassLoader加载,jdk里的类是通过哪个加载器加载的?

PHP中文网PHP中文网2741 days ago351

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 10:22:06

    String’s class loader is bootstrap class loader. Class loading in this way will be displayed as null

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 10:22:06

    String is loaded by the bootstrap class loader, and 引导类加载器 is implemented in native C++ code and does not inherit from java.lang.ClassLoader. We cannot obtain this class loader in the program of.

    reply
    0
  • Cancelreply