📄 chap06.html
字号:
<I><P><FONT FACE="Courier New">class_index</FONT></P>
</I><P>The <FONT FACE="Courier New">class_index</FONT> gives the index of the <FONT FACE="Courier New">CONSTANT_Class_info</FONT> entry for the class that declares the referenced field.</P>
<P>Note that the <FONT FACE="Courier New">CONSTANT_Class_info</FONT> specified by <FONT FACE="Courier New">class_index</FONT> must represent a class and not an interface. Although interfaces can declare fields, those fields are by definition public, static, and final. As mentioned in earlier chapters, class files do not contain symbolic references to static final fields of other classes. Instead, class files contain a copy of the constant value of any static final fields it uses. For example, if a class uses a static final field of type <FONT FACE="Courier New">float</FONT> that is declared in an interface, the class would have a <FONT FACE="Courier New">CONSTANT_Float_info</FONT> table in its own constant pool that stores the <FONT FACE="Courier New">float</FONT> value. For more information about this special treatment of static final fields, see Chapter 8, "The Linking Model."</P>
<I><P><FONT FACE="Courier New">name_and_type_index</FONT></P>
</I><P>The <FONT FACE="Courier New">name_and_type_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> entry that gives the field韘 simple name and descriptor.</P>
<H3><P>The CONSTANT_Methodref_info Table</P>
</H3><P>The <FONT FACE="Courier New">CONSTANT_Methodref_info</FONT> table represents a symbolic reference to a method declared in a class (not in an interface). Table 6-17 shows the format of a <FONT FACE="Courier New">CONSTANT_Methodref_info</FONT> table.</P>
<P>Table 6-17. Format of a <FONT FACE="Courier New">CONSTANT_Methodref_info</FONT> table</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Type</STRONG></TD><TD VALIGN="TOP"><STRONG>Name </STRONG></TD><TD VALIGN="TOP"><STRONG>Count</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u1</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">tag</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">class_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">name_and_type_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
</TABLE>
<I><P><FONT FACE="Courier New">tag</FONT></P>
</I><P>The <FONT FACE="Courier New">tag</FONT> item has the value <FONT FACE="Courier New">CONSTANT_Methodref</FONT> (10).</P>
<I><P><FONT FACE="Courier New">class_index</FONT></P>
</I><P>The <FONT FACE="Courier New">class_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_Class_info</FONT> entry for the class that declares the referenced method. The <FONT FACE="Courier New">CONSTANT_Class_info</FONT> table specified by <FONT FACE="Courier New">class_index</FONT> must be a class and not an interface. Symbolic references to methods declared in interfaces use <FONT FACE="Courier New">CONSTANT_InterfaceMethodref</FONT>.</P>
<I><P><FONT FACE="Courier New">name_and_type_index</FONT></P>
</I><P>The <FONT FACE="Courier New">name_and_type_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> entry that gives the method韘 simple name and descriptor.</P>
<H3><P>The CONSTANT_InterfaceMethodref_info Table</P>
</H3><P>The <FONT FACE="Courier New">CONSTANT_InterfaceMethodref_info</FONT> table represents a symbolic reference to a method declared in an interface (not in a class). Table 6-18 shows the format of a <FONT FACE="Courier New">CONSTANT_InterfaceMethodref_info</FONT> table.</P>
<P>Table 6-18. Format of a <FONT FACE="Courier New">CONSTANT_InterfaceMethodref_info</FONT> table</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Type</STRONG></TD><TD VALIGN="TOP"><STRONG>Name </STRONG></TD><TD VALIGN="TOP"><STRONG>Count</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u1</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">tag</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">class_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">name_and_type_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
</TABLE>
<I><P><FONT FACE="Courier New">tag</FONT></P>
</I><P>The <FONT FACE="Courier New">tag</FONT> item has the value <FONT FACE="Courier New">CONSTANT_InterfaceMethodref</FONT> (11).</P>
<I><P><FONT FACE="Courier New">class_index</FONT></P>
</I><P>The <FONT FACE="Courier New">class_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_Class_info</FONT> entry for the interface that declares the referenced method. The <FONT FACE="Courier New">CONSTANT_Class_info</FONT> table specified by <FONT FACE="Courier New">class_index</FONT> must be an interface and not a class. Symbolic references to methods declared in classes use <FONT FACE="Courier New">CONSTANT_Methodref</FONT>.</P>
<I><P><FONT FACE="Courier New">name_and_type_index</FONT></P>
</I><P>The <FONT FACE="Courier New">name_and_type_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> entry that gives the method韘 simple name and descriptor.</P>
<H3><P>The CONSTANT_NameAndType_info Table</P>
</H3><P>The <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> table forms part of a symbolic reference to a field or method. This table gives constant pool entries of the simple name and the descriptor of the referenced field or method. Table 6-19 shows the format of a <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> table.</P>
<P>Table 6-19. Format of a <FONT FACE="Courier New">CONSTANT_NameAndType_info</FONT> table</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Type</STRONG></TD><TD VALIGN="TOP"><STRONG>Name </STRONG></TD><TD VALIGN="TOP"><STRONG>Count</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u1</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">tag</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">name_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">descriptor_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
</TABLE>
<I><P><FONT FACE="Courier New">tag</FONT></P>
</I><P>The <FONT FACE="Courier New">tag</FONT> item has the value <FONT FACE="Courier New">CONSTANT_NameAndType</FONT> (12).</P>
<I><P><FONT FACE="Courier New">name_index</FONT></P>
</I><P>The <FONT FACE="Courier New">name_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_Utf8_info</FONT> entry that gives the name of the field or method.</P>
<I><P><FONT FACE="Courier New">descriptor_index</FONT></P>
</I><P>The <FONT FACE="Courier New">descriptor_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_Utf8_info</FONT> entry that gives the descriptor of the field or method.</P>
<H3><EM><P>Fields</P>
</EM></H3><P>Each field (class variable and instance variable) declared in a class or interface is described by a <FONT FACE="Courier New">field_info</FONT> table in the class file. The format of the <FONT FACE="Courier New">field_info</FONT> table is shown in Table 6-20.</P>
<P>Table 6-20. Format of a <FONT FACE="Courier New">field_info</FONT> table</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Type</STRONG></TD><TD VALIGN="TOP"><STRONG>Name </STRONG></TD><TD VALIGN="TOP"><STRONG>Count</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">access_flags</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">name_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">descriptor_index</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">u2</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">attributes_count</FONT></TD><TD VALIGN="TOP">1</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">attribute_info</FONT></TD><TD VALIGN="TOP"><FONT FACE="Courier New">attributes</FONT> </TD><TD VALIGN="TOP"><FONT FACE="Courier New">attributes_count</FONT></TD></TR>
</TABLE>
<H3><P>access_flags</P>
</H3><P>The modifiers used in declaring the field are placed into the field韘 <FONT FACE="Courier New">access_flags</FONT> item. Table 6-21 shows the bits used by each flag.</P>
<P>Table 6-21. Flags in the <FONT FACE="Courier New">access_flags</FONT> item of <FONT FACE="Courier New">field_info</FONT> tables</P>
<TABLE WIDTH="500">
<TR><TD VALIGN="TOP"><STRONG>Flag Name</STRONG></TD><TD VALIGN="TOP"><STRONG>Value</STRONG></TD><TD VALIGN="TOP"><STRONG>Meaning if Set</STRONG></TD><TD VALIGN="TOP"><STRONG>Set By</STRONG></TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_PUBLIC</FONT></TD><TD VALIGN="TOP">0x0001</TD><TD VALIGN="TOP">Field is public</TD><TD VALIGN="TOP">Classes and interfaces</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_PRIVATE</FONT></TD><TD VALIGN="TOP">0x0002</TD><TD VALIGN="TOP">Field is private</TD><TD VALIGN="TOP">Classes only</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_PROTECTED</FONT></TD><TD VALIGN="TOP">0x0004</TD><TD VALIGN="TOP">Field is protected</TD><TD VALIGN="TOP">Classes only</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_STATIC</FONT></TD><TD VALIGN="TOP">0x0008</TD><TD VALIGN="TOP">Field is static</TD><TD VALIGN="TOP">Classes and interfaces</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_FINAL</FONT></TD><TD VALIGN="TOP">0x0010</TD><TD VALIGN="TOP">Field is final</TD><TD VALIGN="TOP">Classes and interfaces</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_VOLATILE</FONT></TD><TD VALIGN="TOP">0x0040</TD><TD VALIGN="TOP">Field is volatile</TD><TD VALIGN="TOP">Classes only</TD></TR>
<TR><TD VALIGN="TOP"><FONT FACE="Courier New">ACC_TRANSIENT</FONT></TD><TD VALIGN="TOP">0x0080</TD><TD VALIGN="TOP">Field is transient</TD><TD VALIGN="TOP">Classes only</TD></TR>
</TABLE>
<P>For fields declared in a class (not an interface), at most one of <FONT FACE="Courier New">ACC_PUBLIC</FONT>, <FONT FACE="Courier New">ACC_PRIVATE</FONT>, and <FONT FACE="Courier New">ACC_PROTECTED</FONT> may be set. <FONT FACE="Courier New">ACC_FINAL</FONT> and <FONT FACE="Courier New">ACC_VOLATILE</FONT> must not both be set. All fields declared in interfaces must have the <FONT FACE="Courier New">ACC_PUBLIC</FONT>, <FONT FACE="Courier New">ACC_STATIC</FONT>, and <FONT FACE="Courier New">ACC_FINAL</FONT> flags set.</P>
<P>All unused bits in <FONT FACE="Courier New">access_flags</FONT> must be set to zero and ignored by Java Virtual Machine implementations.</P>
<H3><P>name_index</P>
</H3><P>The <FONT FACE="Courier New">name_index</FONT> gives the index of a <FONT FACE="Courier New">CONSTANT_Utf8_info</FONT> entry that gives the simple (not fully qualified) name of the field.</P>
<H3><P>descriptor_index</P>
</H3><P>The <FONT FACE="Courier New">descriptor_index</FONT> gives t
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -