When we run a Java application, we know that the first object to be loaded is java.lang.Object
. However, java.lang.Object
has methods which throw exceptions like CloneNotSupportedException
or InterruptedException
, which are in turn other objects.
当我们运行Java应用程序时,我们知道要加载的第一个对象是java.lang.Object。但是,java.lang.Object具有抛出异常的方法,如CloneNotSupportedException或InterruptedException,这些异常又是其他对象。
The question is: when java.lang.Object
is just getting loaded, how is it possible to have its child (for example exception objects) objects being already created?
问题是:当java.lang.Object刚刚加载时,如何才能使其子(例如异常对象)对象被创建?
1 个解决方案
#1
3
loaded
andinstantiated
are two different things.加载和实例化是两件事。
Rough explanation:
loaded
means the JVM loaded a class into its base class loader. This makes the class available for instantiation. When JVM starts, it first loads all classes through the used/linked jar
files, without instantiating them. This means, when the first new Object()
is created, the exceptions which are used by Object
are already known. This is still a declaration. The instance of the exception is created only when that particular exception is thrown.
loaded表示JVM将类加载到其基类加载器中。这使该类可用于实例化。当JVM启动时,它首先通过used /链接的jar文件加载所有类,而不实例化它们。这意味着,当创建第一个新Object()时,Object已使用的异常已知。这仍然是一个宣言。只有在抛出该特定异常时才会创建异常实例。
For technically correct explanation see the link which @Jim Garrison has mentioned:
有关技术上正确的解释,请参阅@Jim Garrison提到的链接:
JVM: Loading, Linking, and Initializing
JVM:加载,链接和初始化
#1
3
loaded
andinstantiated
are two different things.加载和实例化是两件事。
Rough explanation:
loaded
means the JVM loaded a class into its base class loader. This makes the class available for instantiation. When JVM starts, it first loads all classes through the used/linked jar
files, without instantiating them. This means, when the first new Object()
is created, the exceptions which are used by Object
are already known. This is still a declaration. The instance of the exception is created only when that particular exception is thrown.
loaded表示JVM将类加载到其基类加载器中。这使该类可用于实例化。当JVM启动时,它首先通过used /链接的jar文件加载所有类,而不实例化它们。这意味着,当创建第一个新Object()时,Object已使用的异常已知。这仍然是一个宣言。只有在抛出该特定异常时才会创建异常实例。
For technically correct explanation see the link which @Jim Garrison has mentioned:
有关技术上正确的解释,请参阅@Jim Garrison提到的链接:
JVM: Loading, Linking, and Initializing
JVM:加载,链接和初始化