📄 classfile.doc.html
字号:
qualified form <a href="Concepts.doc.html#20207">(§2.7.9)</a>. These class names are always represented as
<code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structures, and they are referenced from those
<code>CONSTANT_NameAndType_info</code> <a href="ClassFile.doc.html#1327">(§4.4.6)</a> structures that have class names as part of
their descriptor <a href="ClassFile.doc.html#1169">(§4.3)</a>, as well as from all <code>CONSTANT_Class_info</code> <a href="ClassFile.doc.html#1221">(§4.4.1)</a> structures.
<p><a name="14922"></a>
For historical reasons the exact syntax of fully qualified class names that appear in <code>class</code> file structures differs from the familiar Java fully qualified class name documented in <a href="Concepts.doc.html#20207">§2.7.9</a>. In the internal form, the ASCII periods (<code>'</code>.<code>'</code>) that normally separate the identifiers <a href="Concepts.doc.html#25339">(§2.2)</a> that make up the fully qualified name are replaced by ASCII forward slashes (<code>'/'</code>). For example, the normal fully qualified name of class <code>Thread</code> is <code>java.lang.Thread</code>. In the form used in descriptors in <code>class</code> files, a reference to the name of class <code>Thread</code> is implemented using a <code>CONSTANT_Utf8_info</code> structure representing the string <code>"java/lang/Thread"</code>.<p>
<a name="1169"></a>
<hr><h2>4.3 Descriptors</h2>
<a name="1170"></a>
A descriptor is a string representing the type of a field or method.
<p><a name="13972"></a>
<h3>4.3.1 Grammar Notation</h3>
<a name="14150"></a>
Descriptors are specified using a grammar. This grammar is a set of productions that
describe how sequences of characters can form syntactically correct descriptors of
various types. Terminal symbols of the grammar are shown in bold fixed-width font.
Nonterminal symbols are shown in <i>italic</i> type. The definition of a nonterminal is
introduced by the name of the nonterminal being defined, followed by a colon. One
or more alternative right-hand sides for the nonterminal then follow on succeeding
lines. A nonterminal symbol on the right-hand side of a production that is followed
by an asterisk (*) represents zero or more possibly different values produced from
that nonterminal, appended without any intervening space.
<p><a name="14152"></a>
<h3>4.3.2 Field Descriptors</h3>
<a name="7028"></a>
A <i>field descriptor</i> represents the type of a class or instance variable. It is a series of
characters generated by the grammar:
<p><a name="23538"></a>
<i>FieldDescriptor:</i><br><blockquote><a name="23539"></a>
<i>FieldType</i><p>
</blockquote><a name="23540"></a>
<p>
<a name="23546"></a>
<i>ComponentType:</i><br><blockquote><a name="13979"></a>
<i>FieldType</i><p>
</blockquote><a name="23520"></a>
<p>
<a name="23545"></a>
<i>FieldType:</i><br><blockquote><a name="13982"></a>
<i>BaseType</i><p>
<a name="14135"></a>
<i>ObjectType</i><p>
<a name="13983"></a>
<i>ArrayType</i> <p>
</blockquote><a name="13984"></a>
<p>
<a name="23547"></a>
<i>BaseType:</i><br><blockquote><a name="13985"></a>
B<p>
<a name="13986"></a>
C<p>
<a name="13987"></a>
D<p>
<a name="13988"></a>
F<p>
<a name="13989"></a>
I<p>
<a name="13990"></a>
J<p>
<a name="13991"></a>
S<p>
<a name="13992"></a>
Z<p>
<a name="14125"></a>
<p>
</blockquote><a name="23548"></a>
<i>ObjectType:</i><br><blockquote><a name="14126"></a>
L <classname> ;<p>
</blockquote><a name="14127"></a>
<i>ArrayType:</i><br><blockquote><a name="14128"></a>
[ <i>ComponentType</i><p>
</blockquote><a name="14019"></a>
The characters of <i>BaseType</i>, the L and ; of <i>ObjectType</i>, and the [ of <i>ArrayType</i> are all ASCII characters. The <classname> represents a fully qualified class name, for instance, <code>java.lang.Thread</code>. For historical reasons it is stored in a <code>class</code> file in a modified internal form (<a href="ClassFile.doc.html#14757">§4.2)</a>.<p>
<a name="16252"></a>
The meaning of the field types is as follows:<p>
<pre><a name="16253"></a>
B <code>byte </code> signed byte <br> C <code>char</code> character <br> D <code>double </code> double-precision IEEE 754 float <br> F <code>float </code> single-precision IEEE 754 float <br> I <code>int </code> integer <br> J <code>long </code> long integer <br> L<classname>;<code> </code>... an instance of the class <br> S <code>short</code> signed short <br> Z <code>boolean </code> <code>true</code> or <code>false </code> <br> [<code> </code>... one array dimension<p><br></pre><a name="23302"></a>
For example, the descriptor of an <code>int</code> instance variable is simply I. The descriptor of
an instance variable of type <code>Object</code> is Ljava/lang/Object;. Note that the internal form of
the fully qualified class name for class <code>Object</code> is used. The descriptor of an instance
variable that is a multidimensional <code>double</code> array,
<p><pre> <code>double d[][][];
</code></pre><a name="12776"></a>
is
<p><pre> <strong>[[[D
</strong></pre><a name="7035"></a>
<h3>4.3.3 Method Descriptors</h3>
<a name="7597"></a>
A <i>parameter descriptor </i>represents a parameter passed to a method:
<p><a name="23526"></a>
<i>ParameterDescriptor:</i><br><blockquote><a name="23527"></a>
<i>FieldType</i><p>
</blockquote><a name="23528"></a>
A <i>method descriptor</i> represents the parameters that the method takes and the value that it returns:<p>
<a name="14037"></a>
<i>MethodDescriptor:</i><br><blockquote><a name="14038"></a>
( <i>ParameterDescriptor * </i>) <i>ReturnDescriptor</i><p>
</blockquote><a name="7585"></a>
A <i>return descriptor </i>represents the return value from a method. It is a series of characters generated by the grammar:<p>
<a name="14049"></a>
<i>ReturnDescriptor:</i><br><blockquote><a name="14050"></a>
<i>FieldType</i><p>
<a name="14051"></a>
V<p>
</blockquote><a name="7587"></a>
The character V indicates that the method returns no value (its return type is <code>void</code>). Otherwise, the descriptor indicates the type of the return value.<p>
<a name="11151"></a>
A valid Java method descriptor must represent 255 or fewer words of method parameters, where that limit includes the word for <code>this</code> in the case of instance method invocations. The limit is on the number of words of method parameters and not on the number of parameters themselves; parameters of type <code>long</code> and <code>double</code> each use two words.<p>
<a name="12746"></a>
For example, the method descriptor for the method<p>
<pre> <code>Object mymethod(int i, double d, Thread t)
</code></pre><a name="12751"></a>
is
<p><pre> <strong>(IDLjava/lang/Thread;)Ljava/lang/Object;
</strong></pre><a name="18238"></a>
Note that internal forms of the fully qualified class names of <code>Thread</code> and <code>Object</code> are
used in the method descriptor.
<p><a name="15525"></a>
The method descriptor for <code>mymethod</code> is the same whether <code>mymethod</code> is <code>static</code> or is an instance method. Although an instance method is passed <code>this</code>, a reference to the current class instance, in addition to its intended parameters, that fact is not reflected in the method descriptor. (A reference to <code>this</code> is not passed to a <code>static</code> method.) The reference to <code>this</code> is passed implicitly by the method invocation instructions of the Java Virtual Machine used to invoke instance methods.<p>
<a name="20080"></a>
<hr><h2>4.4 Constant Pool</h2>
<a name="9597"></a>
All <code>constant_pool</code> table entries have the following general format:
<p><pre><br><a name="9604"></a> <code>cp_info {
</code></pre><pre> <code> u1 tag;
</code> <code> u1 info[];
</code><a name="9689"></a> <code>}
</code><br></pre><a name="9691"></a>
Each item in the <code>constant_pool</code> table must begin with a 1-byte tag indicating the kind
of <code>cp_info</code> entry. The contents of the <code>info</code> array varies with the value of <code>tag</code>. The valid
tags and their values are listed in <a href="ClassFile.doc.html#9691">Table 4.2</a><p><Table Border="0">
<tr><th><b><i>Constant Type
</i></b>
<th><b><i>Value
</i></b>
<tr><td><a name="9646"></a>
<code>CONSTANT_Class</code>
<td><a name="9648"></a>
<code>7</code>
<tr><td><a name="9650"></a>
<code>CONSTANT_Fieldref</code>
<td><a name="9652"></a>
<code>9</code>
<tr><td><a name="9654"></a>
<code>CONSTANT_Methodref</code>
<td><a name="9656"></a>
<code>10</code>
<tr><td><a name="9658"></a>
<code>CONSTANT_InterfaceMethodref</code>
<td><a name="9660"></a>
<code>11</code>
<tr><td><a name="9662"></a>
<code>CONSTANT_String</code>
<td><a name="9664"></a>
<code>8</code>
<tr><td><a name="9666"></a>
<code>CONSTANT_Integer</code>
<td><a name="9668"></a>
<code>3</code>
<tr><td><a name="9670"></a>
<code>CONSTANT_Float</code>
<td><a name="9672"></a>
<code>4</code>
<tr><td><a name="9674"></a>
<code>CONSTANT_Long</code>
<td><a name="9676"></a>
<code>5</code>
<tr><td><a name="9678"></a>
<code>CONSTANT_Double</code>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -