问题描述
我正在阅读Java中的类加载方法。
I'm reading on class loading in Java.
假设我们有一个看起来像这样的类加载器层次结构,我知道 First
不能直接由 Second
加载的类访问(反之亦然)。
Assuming we have a classloader hierarchy that looks like this, I understand that classes loaded by First
are not directly accessible by classes loaded by Second
(and vice versa).
Bootstrap
|
System
|
Common
/ \
First Second
我也理解一个类加载器检查其父类加载器是否可以加载该类,如果是,则将加载委托给其父类。
I also understand that a classloader checks with its parent class loader whether it can load the class and, if that is the case, delegates the loading to its parent.
类加载器实际上如何确定它们是否可以加载某些给定的类?
How do classloaders actually determine whether they can load some given class?
推荐答案
根据类加载器的实现而有所不同。但是
That differs depending on the implementation of the classloader. But all Classes a ClassLoader can load are retrieved by ClassLoader.findClass(String)
有很多实现,但是最常见的是可从目录和jar文件中加载类。
There are many implementations but the most common one is the URLClassLoader which loads classes from directories and jar files.
这篇关于Classloader如何确定可以加载哪些类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!