📄 classfile.doc.html
字号:
Is <code>static</code>.
<td><a name="23436"></a>
Any field
<tr><td><a name="23438"></a>
<code>ACC_FINAL</code>
<td><a name="23440"></a>
<code>0x0010</code>
<td><a name="23442"></a>
Is <code>final</code>; no further overriding or assignment after initialization.
<td><a name="23444"></a>
Any field
<tr><td><a name="23446"></a>
<code>ACC_VOLATILE</code>
<td><a name="23448"></a>
<code>0x0040</code>
<td><a name="23450"></a>
Is <code>volatile;</code> cannot be cached.
<td><a name="23452"></a>
Class field
<tr><td><a name="23454"></a>
<code>ACC_TRANSIENT</code>
<td><a name="23456"></a>
<code>0x0080</code>
<td><a name="23458"></a>
Is <code>transient</code>; not written or read by a persistent object manager.
<td><a name="23460"></a>
Class field
</Table><br><br><p>
<a name="23473"></a>
Fields of interfaces may only use flags indicated in <a href="ClassFile.doc.html#23392">Table 4.3</a> as used by any field. Fields of classes may use any of the flags in <a href="ClassFile.doc.html#23392">Table 4.3</a>. <p>
<a name="23057"></a>
All unused bits of the <code>access_flags</code> item, including those not assigned in <a href="ClassFile.doc.html#23392">Table 4.3</a>, are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java Virtual Machine implementations.<p>
<a name="23061"></a>
Class fields may have at most one of flags <code>ACC_PUBLIC</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PRIVATE</code> set <a href="Concepts.doc.html#18914">(§2.7.8)</a>. A class field may not have both <code>ACC_FINAL</code> and <code>ACC_VOLATILE</code> set <a href="Concepts.doc.html#16297">(§2.9.1)</a>.<p>
<a name="22231"></a>
Each interface field is implicitly <code>static</code> and <code>final</code> <a href="Concepts.doc.html#18349">(§2.13.4)</a> and must have both its <code>ACC_STATIC</code> and <code>ACC_FINAL</code> flags set. Each interface field is implicitly <code>public</code> <a href="Concepts.doc.html#18349">(§2.13.4)</a> and must have its <code>ACC_PUBLIC</code> flag set.<p>
</blockquote><a name="22218"></a>
<b> name_index</b><br><blockquote><a name="3976"></a>
The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure which must represent a valid Java field name <a href="Concepts.doc.html#21272">(§2.7)</a> stored as a simple (not fully qualified) name <a href="Concepts.doc.html#21410">(§2.7.1)</a>, that is, as a Java identifier.<p>
</blockquote><a name="1497"></a>
<b> descriptor_index</b><br><blockquote><a name="1498"></a>
The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure which must represent a valid Java field descriptor <a href="ClassFile.doc.html#14152">(§4.3.2)</a>.<p>
</blockquote><a name="1499"></a>
<b> attributes_count</b><br><blockquote><a name="1500"></a>
The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#1442">(§4.7)</a> of this field.<p>
</blockquote><a name="1501"></a>
<b> attributes[]</b><br><blockquote><a name="1502"></a>
Each value of the <code>attributes</code> table must be a variable-length attribute structure. A field can have any number of attributes <a href="ClassFile.doc.html#1442">(§4.7)</a> associated with it. <p>
<a name="14292"></a>
The only attribute defined for the <code>attributes</code> table of a <code>field_info</code> structure by this specification is the <code>ConstantValue</code> attribute <a href="ClassFile.doc.html#1405">(§4.7.3)</a>. <p>
<a name="14304"></a>
A Java Virtual Machine implementation must recognize <code>ConstantValue</code> attributes in the <code>attributes</code> table of a <code>field_info</code> structure. A Java Virtual Machine implementation is required to silently ignore any or all other attributes in the <code>attributes</code> table that it does not recognize. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(§4.7.1)</a>.<p>
</blockquote><a name="1513"></a>
<hr><h2>4.6 Methods</h2>
<a name="1514"></a>
Each method, and each instance initialization method <code><init></code>, is described by a variable-length <code>method_info</code> structure. The structure has the following format:
<p><pre><br><a name="1515"></a> <code>method_info {
</code></pre><pre> <code> u2 access_flags;
</code> <code> u2 name_index;
</code> <code> u2 descriptor_index;
</code> <code> u2 attributes_count;
</code> <code> attribute_info attributes[attributes_count];
</code><a name="1521"></a> <code>}
</code><br></pre><a name="9412"></a>
The items of the <code>method_info</code> structure are as follows:
<p><a name="1522"></a>
<b> access_flags</b><br><blockquote><a name="12725"></a>
The value of the <code>access_flags</code> item is a mask of modifiers used to describe access permission to and properties of a method or instance initialization method <a href="Overview.doc.html#12174">(§3.8)</a>. The <code>access_flags</code> modifiers are shown in Table 4.4. <p><Table Border="0">
<tr><td><a name="12562"></a>
Flag Name
<td><a name="12564"></a>
Value
<td><a name="12566"></a>
Meaning
<td><a name="12568"></a>
Used By
<tr><td><a name="12570"></a>
<code>ACC_PUBLIC</code>
<td><a name="12572"></a>
<code>0x0001</code>
<td><a name="12574"></a>
Is <code>public</code>; may be accessed from outside its package.
<td><a name="12576"></a>
Any method
<tr><td><a name="12578"></a>
<code>ACC_PRIVATE</code>
<td><a name="12580"></a>
<code>0x0002</code>
<td><a name="12582"></a>
Is <code>private</code>; usable only within the defining class.
<td><a name="12584"></a>
Class/instance method
<tr><td><a name="12586"></a>
<code>ACC_PROTECTED</code>
<td><a name="12588"></a>
<code>0x0004</code>
<td><a name="12590"></a>
Is <code>protected</code>; may be accessed within subclasses.
<td><a name="12592"></a>
Class/instance method
<tr><td><a name="12594"></a>
<code>ACC_STATIC</code>
<td><a name="12596"></a>
<code>0x0008</code>
<td><a name="12598"></a>
Is <code>static</code>.
<td><a name="12600"></a>
Class/instance method
<tr><td><a name="12602"></a>
<code>ACC_FINAL</code>
<td><a name="12604"></a>
<code>0x0010</code>
<td><a name="12606"></a>
Is <code>final</code>; no overriding is allowed.
<td><a name="12608"></a>
Class/instance method
<tr><td><a name="12610"></a>
<code>ACC_SYNCHRONIZED</code>
<td><a name="12612"></a>
<code>0x0020</code>
<td><a name="12614"></a>
Is <code>synchronized</code>; wrap use in monitor lock.
<td><a name="12616"></a>
Class/instance method
<tr><td><a name="12634"></a>
<code>ACC_NATIVE</code>
<td><a name="12636"></a>
<code>0x0100</code>
<td><a name="12638"></a>
Is <code>native</code>; implemented in a language other than Java.
<td><a name="12640"></a>
Class/instance method
<tr><td><a name="12650"></a>
<code>ACC_ABSTRACT</code>
<td><a name="12652"></a>
<code>0x0400</code>
<td><a name="12654"></a>
Is <code>abstract</code>; no implementation is provided.
<td><a name="12656"></a>
Any method
</Table><br><br><p>
<a name="13091"></a>
Methods in interfaces may only use flags indicated in <a href="ClassFile.doc.html#12725">Table 4.4</a> as used by any method. Class and instance methods <a href="Concepts.doc.html#16348">(§2.10.3)</a> may use any of the flags in <a href="ClassFile.doc.html#12725">Table 4.4</a>. Instance initialization methods <a href="Overview.doc.html#12174">(§3.8)</a> may only use <code>ACC_PUBLIC</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PRIVATE</code>. <p>
<a name="23221"></a>
All unused bits of the <code>access_flags</code> item, including those not assigned in <a href="ClassFile.doc.html#12725">Table 4.4</a>, are reserved for future use. They should be set to zero in generated <code>class</code> files and should be ignored by Java Virtual Machine implementations.<p>
<a name="1528"></a>
At most one of the flags <code>ACC_PUBLIC</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PRIVATE</code> may be set for any method. Class and instance methods may not use <code>ACC_ABSTRACT</code> together with <code>ACC_FINAL</code>, <code>ACC_NATIVE</code>, or <code>ACC_SYNCHRONIZED</code> (that is, <code>native</code> and <code>synchronized</code> methods require an implementation). A class or instance method may not use <code>ACC_PRIVATE</code> with <code>ACC_ABSTRACT</code> (that is, a <code>private</code> method cannot be overridden, so such a method could never be implemented or used). A class or instance method may not use <code>ACC_STATIC</code> with <code>ACC_ABSTRACT</code> (that is, a <code>static</code> method is implicitly <code>final</code> and thus cannot be overridden, so such a method could never be implemented or used).<p>
<a name="22379"></a>
Class and interface initialization methods <a href="Overview.doc.html#12174">(§3.8)</a>, that is, methods named <code><clinit></code>, are called implicitly by the Java Virtual Machine; the value of their <code>access_flags</code> item is ignored.<p>
<a name="13128"></a>
Each interface method is implicitly <code>abstract</code>, and so must have its <code>ACC_ABSTRACT</code> flag set. Each interface method is implicitly <code>public</code> <a href="Concepts.doc.html#20648">(§2.13.5)</a>, and so must have its <code>ACC_PUBLIC</code> flag set.<p>
</blockquote><a name="1529"></a>
<b> name_index</b><br><blockquote><a name="1530"></a>
The value of the <code>name_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure representing either one of the special internal method names <a href="Overview.doc.html#12174">(§3.8)</a>, either <code><init></code> or <code><clinit></code>, or a valid Java method name <a href="Concepts.doc.html#21272">(§2.7)</a>, stored as a simple (not fully qualified) name <a href="Concepts.doc.html#21410">(§2.7.1)</a>.<p>
</blockquote><a name="1531"></a>
<b> descriptor_index</b><br><blockquote><a name="1532"></a>
The value of the <code>descriptor_index</code> item must be a valid index into the <code>constant_pool</code> table. The <code>constant_pool</code> entry at that index must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure representing a valid Java method descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a>.<p>
</blockquote><a name="1533"></a>
<b> attributes_count</b><br><blockquote><a name="1534"></a>
The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#1442">(§4.7)</a> of this method.<p>
</blockquote><a name="1535"></a>
<b> attributes[]</b><br><blockquote><a name="3097"></a>
Each value of the <code>attributes</code> table must be a variable-length attribute structure. A method can have any number of optional attributes <a href="ClassFile.doc.html#1442">(§4.7)</a> associated with it. <p>
<a name="15279"></a>
The only attributes defined by this specification for the <code>attributes</code> table of a <code>method_info</code> structure are the <code>Code</code> <a href="ClassFile.doc.html#1546">(§4.7.4)</a> and <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(§4.7.5)</a> attributes. <p>
<a name="14336"></a>
A Java Virtual Machine implementation must recognize <code>Code</code> <a href="ClassFile.doc.html#1546">(§4.7.4)</a> and <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(§4.7.5)</a> attributes. A Java Virtual Machine implementation is required to silently ignore any or all other attributes in the <code>attributes</code> table of a <code>method_info</code> structure that it does not recognize. Attributes not defined in this specification are not allowed to affect the semantics of the <code>class</code> file, but only to provide additional descriptive information <a href="ClassFile.doc.html#16733">(§4.7.1)</a>.<p>
</blockquote><a name="1442"></a>
<hr><h2>4.7 Attributes</h2>
<a name="1711"></a>
Attributes are used in the <code>ClassFile</code> <a href="ClassFile.doc.html#21045">(§4.1)</a>, <code>field_info</code> <a href="ClassFile.doc.html#2877">(§4.5)</a>, <code>method_info</code> <a href="ClassFile.doc.html#1513">(§4.6)</a>, and
<code>Code_attribute</code> <a href="ClassFile.doc.html#1546">(§4.7.4)</a> structures of the <code>class</code> file format. All attributes have the following general format:
<p><pre><br><a name="1712"></a> <code>attribute_info {
</code></pre><pre> <code> u2 attribute_name_index;
</code> 
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -