📄 constantpool.doc.html
字号:
<li>If the field descriptor represents a non-array reference type (its first character is "<code>L</code>"), that reference type is the base type of the array class. The reference type is itself resolved using the procedures indicated above in <a href="ConstantPool.doc.html#65190">§5.1.1</a> or in <a href="ConstantPool.doc.html#67374">§5.1.2</a>.
</ul><ol>
<a name="65711"></a>
<li>If an array class representing the same base type and the same number of dimensions has already been created, the result of the resolution is that array class. Otherwise, a new array class representing the indicated base type and number of dimensions is created.
</ol>
<a name="49425"></a>
<hr><h2>5.2 Field and Method Resolution</h2>
<a name="61431"></a>
A constant pool entry tagged as <code>CONSTANT_Fieldref</code> <a href="ClassFile.doc.html#4723">(§4.4.2)</a> represents a class or
instance variable <a href="Concepts.doc.html#16338">(§2.9)</a> or a (constant) field of an interface <a href="Concepts.doc.html#18349">(§2.13.4)</a>. Note that
interfaces do not have instance variables. A constant pool entry tagged as
<code>CONSTANT_Methodref</code> <a href="ClassFile.doc.html#4723">(§4.4.2)</a> represents a method of a class (a <code>static</code> method) or of a
class instance (an instance method). References to interface methods are made using
<code>CONSTANT_InterfaceMethodref</code> constant pool entries; resolution of such entries is
described in <a href="ConstantPool.doc.html#64064">§5.3</a>.
<p><a name="51523"></a>
To resolve a field reference or a method reference, the <code>CONSTANT_Class</code> <a href="ClassFile.doc.html#1221">(§4.4.1)</a> entry representing the class of which the field or method is a member must first be successfully resolved (<a href="ConstantPool.doc.html#51579">§5.1)</a>. Thus, any exception that can be thrown when resolving a <code>CONSTANT_Class</code> constant pool entry can also be thrown as a result of resolving a <code>CONSTANT_Fieldref</code> or <code>CONSTANT_Methodref</code> entry. If the <code>CONSTANT_Class</code> entry representing the class or interface can be successfully resolved, exceptions relating to the linking of the method or field itself can be thrown. When resolving a field reference:<p>
<ul><a name="51536"></a>
<li>If the referenced field does not exist in the specified class or interface, field resolution throws a <code>NoSuchFieldError</code>.
<a name="51537"></a>
<li>Otherwise, if the current class does not have permission to access the referenced field, field resolution throws an <code>IllegalAccessError</code> exception.
</ul><a name="51544"></a>
If resolving a method:
<p><ul><a name="51548"></a>
<li>If the referenced method does not exist in the specified class or interface, field resolution throws a <code>NoSuchMethodError</code>.
<a name="51549"></a>
<li>Otherwise, if the current class does not have permission to access the method being resolved, method resolution throws an <code>IllegalAccessError</code> exception.
</ul><a name="64064"></a>
<hr><h2>5.3 Interface Method Resolution</h2>
<a name="64062"></a>
A constant pool entry tagged as <code>CONSTANT_InterfaceMethodref</code> <a href="ClassFile.doc.html#4723">(§4.4.2)</a> represents a
call to an instance method declared by an interface. Such a constant pool entry is
resolved by converting it into a machine-dependent internal format. No error or
exception is possible except for those documented in <a href="Instructions.doc.html#66654">§6.3</a>.
<p><a name="38759"></a>
<hr><h2>5.4 String Resolution</h2>
<a name="38811"></a>
A constant pool entry tagged as <code>CONSTANT_String</code> (<a href="ClassFile.doc.html#8794">§4.4.3)</a> represents an instance of
a string literal <a href="Concepts.doc.html#23152">(§2.3)</a>, that is, a literal of the built-in type <code>java.lang.String</code>. The Unicode
characters <a href="Concepts.doc.html#25310">(§2.1)</a> of the string literal represented by the <code>CONSTANT_String</code> entry are
found in the <code>CONSTANT_Utf8</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> constant pool entry that the <code>CONSTANT_String</code>
entry references.
<p><a name="65142"></a>
The Java language requires that identical string literals (that is, literals that contain the same sequence of Unicode characters) must reference the same instance of class <code>String</code>. In addition, if the method <code>intern</code> is called on any string, the result is a reference to the same class instance that would be returned if that string appeared as a literal. Thus,<p>
<pre> ("a" + "b" + "c").intern() == "abc"
</pre><a name="65011"></a>
must have the value <code>true</code>.<a href="#65169"><sup>3</sup></a>
<p><a name="64955"></a>
To resolve a constant pool entry tagged <code>CONSTANT_String</code>, the Java Virtual Machine examines the series of Unicode characters represented by the UTF-8 string that the <code>CONSTANT_String</code> entry references. <p>
<ul><a name="64977"></a>
<li>If another constant pool entry tagged <code>CONSTANT_String</code> and representing the identical sequence of Unicode characters has already been resolved, then the result of resolution is a reference to the instance of class <code>String</code> created for that earlier constant pool entry.
<a name="65026"></a>
<li>Otherwise, if the method <code>intern</code> has previously been called on an instance of class <code>String</code> containing a sequence of Unicode characters identical to that represented by the constant pool entry, then the result of resolution is a reference to that same instance of class <code>String</code>.
<a name="64978"></a>
<li>Otherwise, a new instance of class <code>String</code> is created containing the sequence of Unicode characters represented by the <code>CONSTANT_String</code> entry; that class instance is the result of resolution.
</ul><a name="65122"></a>
No error or exception is possible during string resolution except for those documented in <a href="Instructions.doc.html#66654">§6.3</a>.<p>
<a name="49466"></a>
<hr><h2>5.5 Resolution of Other Constant Pool Items</h2>
<a name="51636"></a>
Constant pool entries that are tagged <code>CONSTANT_Integer</code> or <code>CONSTANT_Float</code>
(<a href="ClassFile.doc.html#21942">§4.4.4)</a>, <code>CONSTANT_Long</code> or <code>CONSTANT_Double</code> (<a href="ClassFile.doc.html#1348">§4.4.5)</a> all have values that are
directly represented within the constant pool. Their resolution cannot throw exceptions except for those documented in <a href="Instructions.doc.html#66654">§6.3</a>.
<p><a name="64112"></a>
Constant pool entries that are tagged <code>CONSTANT_NameAndType</code> <a href="ClassFile.doc.html#1327">(§4.4.6)</a>, and <code>CONSTANT_Utf8</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> are never resolved directly. They are only referenced directly or indirectly by other constant pool entries.<p>
<a name="60091"></a>
<p>
<hr>
<sup>1</sup><a name="67167"></a>
Sun's JDK release 1.0.2 only verifies <code>class</code> files that have class loaders; it assumes that <code>class</code> files loaded locally are trusted and do not need verification.<p>
<a name="65949"></a>
<p>
<sup>2</sup><a name="63902"></a>
Future implementations may change the API between the Java Virtual Machine and the class <code>ClassLoader</code>. Specifically, the Java Virtual Machine rather than the class loader will keep track of which classes and interfaces have been loaded by a particular class loader. One possibility is that the <code>loadClass</code> method will be called with a single argument indicating the class or interface to be loaded. The virtual machine will handle the details of linking and initialization and ensure that the class loader is not invoked with the same class or interface name multiple times.<p>
<sup>3</sup><a name="65169"></a>
String literal resolution is not implemented correctly in Sun's JDK release 1.0.2. In that implementation of the Java Virtual Machine, resolving a <code>CONSTANT_String</code> in the constant pool always allocates a new string. Two string literals in two different classes, even if they contained the identical sequence of characters, would never be <code>==</code> to each other. A string literal could never be <code>==</code> to a result of the <code>intern</code> method.<p>
<!-- This inserts footnotes--><p>
<br>
<a href="VMSpecTOC.doc.html">Contents</a> | <a href="ClassFile.doc.html">Prev</a> | <a href="Instructions.doc.html">Next</a> | <a href="Lindholm.INDEX.html">Index</a>
<p>
<font size = -1>Java Virtual Machine Specification <br>
<!--(HTML generated by dkramer on March 31, 1997)-->
<!--
(HTML generated by dkramer on March 25, 1997)-->
<br>
<i><a href="Copyright.doc.html">Copyright © 1996, 1997 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:jvm@java.sun.com">jvm@java.sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -