APIdia Launch Partner
Top Description Methods
java.lang.classfile.constantpool

public sealed Interface Utf8Entry

extends CharSequence, AnnotationConstantValueEntry
permits Utf8EntryImpl
Known Direct Implementers
jdk.internal.classfile.impl.AbstractPoolEntry.Utf8EntryImpl
Imports
java.io.DataInput, java.lang.classfile.AnnotationValue, .MethodModel, java.lang.constant.ClassDesc, .MethodTypeDesc, java.lang.invoke.TypeDescriptor, jdk.internal.classfile.impl.AbstractPoolEntry

Models a CONSTANT_UTF8_info constant, representing strings, in the constant pool of a class file. This describes strings in the Modified UTF-8 format.

The use of a Utf8Entry is represented by a String. Conversions are through ConstantPoolBuilder#utf8Entry(String) and stringValue().

Some uses of Utf8Entry represent field or method descriptor strings, symbolically represented as ClassDesc or MethodTypeDesc, depending on where a Utf8Entry appear. Entries representing such uses are created with ConstantPoolBuilder#utf8Entry(ClassDesc) and ConstantPoolBuilder#utf8Entry(MethodTypeDesc), and they can be converted to symbolic descriptors on a per-use-site basis, such as in AnnotationValue.OfClass#classSymbol() and MethodModel#methodTypeSymbol().

Unlike most constant pool entries, a UTF-8 entry is of flexible length: it is represented as an array structure, with an u2 for the data length in bytes, followed by that number of bytes of Modified UTF-8 data. It can represent at most 65535 bytes of data due to the physical restrictions of u2.

Since
24
Java Virtual Machine Specification
4.4.7 The CONSTANT_Utf8_info Structure
See Also
Modified UTF-8

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

whether this entry describes the same string as the provided string
equalsString
(String
the string to compare to
s
)

Returns whether this entry describes the same string as the provided string.

public boolean

Returns:

whether this entry describes the descriptor string of this field type
isFieldType
(ClassDesc
the field type
desc
)

Returns whether this entry describes the descriptor string of this field type.

public boolean

Returns:

whether this entry describes the descriptor string of this method type
isMethodType
(MethodTypeDesc
the method type
desc
)

Returns whether this entry describes the descriptor string of this method type.

public String

Returns:

the string value for this entry
stringValue
()

Returns the string value for this entry.

Inherited from java.lang.CharSequence:
charAtcharscodePointscomparegetCharsisEmptylengthsubSequencetoString
Inherited from java.lang.classfile.constantpool.AnnotationConstantValueEntry:
constantValue

Method Detail

equalsStringback to summary
public boolean equalsString(String s)

Returns whether this entry describes the same string as the provided string.

Parameters
s:String

the string to compare to

Returns:boolean

whether this entry describes the same string as the provided string

isFieldTypeback to summary
public boolean isFieldType(ClassDesc desc)

Returns whether this entry describes the descriptor string of this field type.

Parameters
desc:ClassDesc

the field type

Returns:boolean

whether this entry describes the descriptor string of this field type

Since
25
isMethodTypeback to summary
public boolean isMethodType(MethodTypeDesc desc)

Returns whether this entry describes the descriptor string of this method type.

Parameters
desc:MethodTypeDesc

the method type

Returns:boolean

whether this entry describes the descriptor string of this method type

Since
25
stringValueback to summary
public String stringValue()

Returns the string value for this entry.

API Note

A Utf8Entry can be used directly as a CharSequence if String functionalities are not strictly desired. If only string equivalence is desired, equalsString should be used. Reduction of string processing can significantly improve class file reading performance.

Returns:String

the string value for this entry

See Also
ConstantPoolBuilder#utf8Entry(String)