As mentioned in JVM specification:
如JVM规范中所述:
There are two kinds of class loaders: the bootstrap class loader
supplied by the Java Virtual Machine, and user-defined class loaders.
Every user-defined class loader is an instance of a subclass of the
abstract class ClassLoader.
Additionally, we know that at JVM startup, the following class loaders are set:
此外,我们知道在JVM启动时,会设置以下类加载器:
- Bootstrap class loader
- Extension or Platform class loader
- System or Application class loader
which seems to be contradictory to what is mentioned in the JVM spec as instead of just the bootstrap class loader, there are other classloaders as well supplied by JVM.
这似乎与JVM规范中提到的内容相矛盾,因为除了引导类加载器之外,JVM还提供了其他类加载器。
更多回答
The extension/platform and system/application class loaders are both "user-defined class loaders". That is to say, they are instances of java.lang.ClassLoader
written in Java code.
扩展/平台和系统/应用程序类加载器都是“用户定义的类加载器”。也就是说,它们是用Java代码编写的java.lang.ClassLoader的实例。
Didnt extension classloader go away as of java 9?
扩展类加载器没有从Java 9中消失吗?
@NathanHughes: Yes, its replaced with PlatformClassLoader
post Java9 with backward compatibility.
@NathanHughes:是的,它被后向兼容的PlatformClassLoader取代。
@Slaw: Is it because the Bootstrap class loader is a native implementation and the other two are Java implementations? As per the javadocs: The Java run-time has the following built-in class loaders: Bootstrap, Platform, and System. So what are the criteria for this user-defined vs. JVM provided categorization if all are provided by JVM itself?
@Slaw:是不是因为Bootstrap类加载器是原生实现,另外两个是Java实现?按照javadoc的说法:Java运行时有以下内置的类加载器:引导、平台和系统。那么,如果所有的分类都是由JVM自己提供的,那么用户定义的分类与JVM提供的分类的标准是什么呢?
The platform and system loaders are not provided by the JVM. They are provided by the standard library (though the implementations are internal). But something has to start things off (i.e., bootstrap the class loading process). This is done by a special class loader built into the JVM itself.
平台和系统加载器不是由JVM提供的。它们由标准库提供(尽管实现是内部的)。但必须有一些东西启动(即引导类加载过程)。这是由JVM本身内置的特殊类加载器来完成的。
我是一名优秀的程序员,十分优秀!