📄 classfile.doc.html
字号:
<td><a name="88367"></a><code>0x0001</code><td><a name="88369"></a>Declared <code>public</code>; may be accessed from outside its package. <tr><td><a name="88373"></a><code>ACC_PRIVATE</code><td><a name="88375"></a><code>0x0002</code><td><a name="88377"></a>Declared <code>private</code>; usable only within the defining class.<tr><td><a name="88381"></a><code>ACC_PROTECTED</code><td><a name="88383"></a><code>0x0004</code><td><a name="88385"></a>Declared <code>protected</code>; may be accessed within subclasses.<tr><td><a name="88389"></a><code>ACC_STATIC</code><td><a name="88391"></a><code>0x0008</code><td><a name="88393"></a>Declared <code>static</code>. <tr><td><a name="88396"></a><code>ACC_FINAL</code><td><a name="88398"></a><code>0x0010</code><td><a name="88400"></a>Declared <code>final</code>; no further assignment after initialization.<tr><td><a name="88404"></a><code>ACC_VOLATILE</code><td><a name="88406"></a><code>0x0040</code><td><a name="88408"></a>Declared <code>volatile</code>; cannot be cached. <tr><td><a name="88412"></a><code>ACC_TRANSIENT</code><td><a name="88414"></a><code>0x0080</code><td><a name="88416"></a>Declared <code>transient</code>; not written or read by a persistent object manager. </Table><br><br><p>Fields of classes may set any of the flags in <a href="ClassFile.doc.html#88358">Table 4.4</a>. However, a specific field of a class may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC</code> flags set <a href="Concepts.doc.html#18914">(§2.7.4)</a> and may not have both its <code>ACC_FINAL</code> and <code>ACC_VOLATILE</code> flags set <a href="Concepts.doc.html#29882">(§2.9.1)</a>.<p>All fields of interfaces must have their <code>ACC_PUBLIC</code>, <code>ACC_STATIC</code>, and <code>ACC_FINAL</code> flags set and may not have any of the other flags in <a href="ClassFile.doc.html#88358">Table 4.4</a> set <a href="Concepts.doc.html#18349">(§2.13.3.1)</a>. <p>All bits of the <code>access_flags</code> item not assigned in <a href="ClassFile.doc.html#88358">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="22218"></a><dt><code>name_index</code><dd> 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 field name <a href="Concepts.doc.html#21272">(§2.7)</a> stored as a simple name <a href="Concepts.doc.html#21410">(§2.7.1)</a>, that is, as a Java programming language identifier <a href="Concepts.doc.html#25339">(§2.2)</a>.<p><a name="1497"></a><dt><code>descriptor_index</code><dd> 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 that must represent a valid field descriptor <a href="ClassFile.doc.html#14152">(§4.3.2)</a>.<p><a name="1499"></a><dt><code>attributes_count</code><dd> The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#43817">(§4.7)</a> of this field.<p><a name="1501"></a><dt><code>attributes[]</code><dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(§4.7)</a>. A field can have any number of attributes associated with it. <p>The attributes defined by this specification as appearing in the <code>attributes</code> table of a <code>field_info</code> structure are the <code>ConstantValue</code> <a href="ClassFile.doc.html#1405">(§4.7.2)</a>, <code>Synthetic</code> <a href="ClassFile.doc.html#80128">(§4.7.6)</a>, and <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(§4.7.10)</a> attributes. <p>A Java virtual machine implementation must recognize and correctly read <code>ConstantValue</code> <a href="ClassFile.doc.html#1405">(§4.7.2)</a> attributes found 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><a name="1513"></a></dl><hr><h2>4.6 Methods</h2><a name="1514"></a>Each method, including each instance initialization method <a href="Overview.doc.html#12174">(§3.9)</a> and the class or interface initialization method <a href="Overview.doc.html#12174">(§3.9)</a>, is described by a <code>method_info</code> structure. No two methods in one <code>class</code> file may have the same name and descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a>.<p><a name="84874"></a>The structure has the following format:<p><pre><br><a name="1515"></a> <code>method_info {</code> <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><dl><dt><code>access_flags</code> <dd> The value of the <code>access_flags</code> item is a mask of flags used to denote access permission to and properties of this method. The interpretation of each flag, when set, is as shown in <a href="ClassFile.doc.html#75568">Table 4.5</a>.<a name="75568"></a><p><Table Border="1"><tr><td><a name="75497"></a><strong>Flag Name</strong><td><a name="75499"></a><strong>Value</strong><td><a name="75501"></a><strong>Interpretation</strong><tr><td><a name="75504"></a><code>ACC_PUBLIC</code><td><a name="75506"></a><code>0x0001</code><td><a name="75508"></a>Declared <code>public</code>; may be accessed from outside its package. <tr><td><a name="75511"></a><code>ACC_PRIVATE</code><td><a name="75513"></a><code>0x0002</code><td><a name="75515"></a>Declared <code>private</code>; accessible only within the defining class.<tr><td><a name="75518"></a><code>ACC_PROTECTED</code><td><a name="75520"></a><code>0x0004</code><td><a name="75522"></a>Declared <code>protected</code>; may be accessed within subclasses.<tr><td><a name="75525"></a><code>ACC_STATIC</code><td><a name="75527"></a><code>0x0008</code><td><a name="75529"></a>Declared <code>static</code>. <tr><td><a name="75533"></a><code>ACC_FINAL</code><td><a name="75535"></a><code>0x0010</code><td><a name="75537"></a>Declared <code>final</code>; may not be overridden.<tr><td><a name="75541"></a><code>ACC_SYNCHRONIZED</code><td><a name="75543"></a><code>0x0020</code><td><a name="75545"></a>Declared <code>synchronized</code>; invocation is wrapped in a monitor lock.<tr><td><a name="75549"></a><code>ACC_NATIVE</code><td><a name="75551"></a><code>0x0100</code><td><a name="75553"></a>Declared <code>native</code>; implemented in a language other than Java.<tr><td><a name="75555"></a><code>ACC_ABSTRACT</code><td><a name="75557"></a><code>0x0400</code><td><a name="75559"></a>Declared <code>abstract</code>; no implementation is provided. <tr><td><a name="75561"></a><code>ACC_STRICT</code><td><a name="75563"></a><code>0x0800</code><td><a name="75565"></a>Declared <code>strictfp</code>; floating-point mode is FP-strict</Table><br><br> <p>Methods of classes may set any of the flags in <a href="ClassFile.doc.html#75568">Table 4.5</a>. However, a specific method of a class may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC </code>flags set <a href="Concepts.doc.html#18914">(§2.7.4)</a>. If such a method has its <code>ACC_ABSTRACT</code> flag set it may not have any of its <code>ACC_FINAL</code>, <code>ACC_NATIVE</code>, <code>ACC_PRIVATE</code>, <code>ACC_STATIC</code>, <code>ACC_STRICT</code>, or <code>ACC_SYNCHRONIZED</code> flags set <a href="Concepts.doc.html#20648">(§2.13.3.2)</a>.<p>All interface methods must have their <code>ACC_ABSTRACT</code> and <code>ACC_PUBLIC</code> flags set and may not have any of the other flags in <a href="ClassFile.doc.html#75568">Table 4.5</a> set <a href="Concepts.doc.html#20648">(§2.13.3.2)</a>.<p>A specific instance initialization method <a href="Overview.doc.html#12174">(§3.9)</a> may have at most one of its <code>ACC_PRIVATE</code>, <code>ACC_PROTECTED</code>, and <code>ACC_PUBLIC</code> flags set and may also have its <code>ACC_STRICT</code> flag set, but may not have any of the other flags in <a href="ClassFile.doc.html#75568">Table 4.5</a> set.<p>Class and interface initialization methods <a href="Overview.doc.html#12174">(§3.9)</a> are called implicitly by the Java virtual machine; the value of their <code>access_flags</code> item is ignored except for the settings of the <code>ACC_STRICT </code>flag.<p>All bits of the <code>access_flags</code> item not assigned in <a href="ClassFile.doc.html#75568">Table 4.5</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="1529"></a><dt><code>name_index</code><dd> 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 method names <a href="Overview.doc.html#12174">(§3.9)</a>, <code><init></code> or <code><clinit></code>, or a valid method name in the Java programming language <a href="Concepts.doc.html#21272">(§2.7)</a>, stored as a simple name <a href="Concepts.doc.html#21410">(§2.7.1)</a>.<p><a name="1531"></a><dt><code>descriptor_index</code><dd> 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 method descriptor <a href="ClassFile.doc.html#7035">(§4.3.3)</a>.<p><a name="1533"></a><dt><code>attributes_count</code><dd> The value of the <code>attributes_count</code> item indicates the number of additional attributes <a href="ClassFile.doc.html#43817">(§4.7)</a> of this method.<p><a name="1535"></a><dt><code>attributes[]</code><dd> Each value of the <code>attributes</code> table must be an attribute structure <a href="ClassFile.doc.html#43817">(§4.7)</a>. A method can have any number of optional attributes associated with it. <p>The only attributes defined by this specification as appearing in 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.3)</a>, <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(§4.7.4)</a>, <code>Synthetic</code> <a href="ClassFile.doc.html#80128">(§4.7.6)</a>, and <code>Deprecated</code> <a href="ClassFile.doc.html#78232">(§4.7.10)</a> attributes. <p>A Java virtual machine implementation must recognize and correctly read <code>Code</code> <a href="ClassFile.doc.html#1546">(§4.7.3)</a> and <code>Exceptions</code> <a href="ClassFile.doc.html#3129">(§4.7.4)</a> attributes found in the <code>attributes</code> table of a <code>method_info</code> structure. 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></dl><a name="43817"></a><hr><h2>4.7 Attributes</h2><a name="43824"></a>Attributes are used in the <code>ClassFile</code> <a href="ClassFile.doc.html#74353">(§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.3)</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> <code> u2 attribute_name_index;</code> <code> u4 attribute_length;</code> <code> u1 info[attribute_length];</code><a name="1716"></a> <code>}</code><br></pre><a name="42211"></a>For all attributes, the <code>attribute_name_index</code> must be a valid unsigned 16-bit index into the constant pool of the class. The <code>constant_pool</code> entry at <code>attribute_name_index</code> must be a <code>CONSTANT_Utf8_info</code> <a href="ClassFile.doc.html#7963">(§4.4.7)</a> structure representing the name of the attribute. The value of the <code>attribute_length</code> item indicates the length of the subsequent information in bytes. The length does not include the initial six bytes that contain the <code>attribute_name_index</code> and <code>attribute_length</code> items.<p><a name="14354"></a>Certain attributes are predefined as part of the <code>class</code> file specification. The predefined attributes are
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -