AnnotationConstantValueEntry, CharSequence, PoolEntrypublic sealed interface Utf8Entry extends CharSequence, AnnotationConstantValueEntry
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.
CONSTANT_Utf8_info StructureTAG_CLASS, TAG_DOUBLE, TAG_DYNAMIC, TAG_FIELDREF, TAG_FLOAT, TAG_INTEGER, TAG_INTERFACE_METHODREF, TAG_INVOKE_DYNAMIC, TAG_LONG, TAG_METHOD_HANDLE, TAG_METHOD_TYPE, TAG_METHODREF, TAG_MODULE, TAG_NAME_AND_TYPE, TAG_PACKAGE, TAG_STRING, TAG_UTF8
| Modifier and Type | Method | Description |
|---|---|---|
boolean |
equalsString |
Returns whether this entry describes the same string as the provided string. |
boolean |
isFieldType |
Returns whether this entry describes the descriptor string of this field type. |
boolean |
isMethodType |
Returns whether this entry describes the descriptor string of this method type. |
String |
stringValue() |
Returns the string value for this entry. |
constantValue
charAt, chars, codePoints, getChars, isEmpty, length, subSequence, toString
constantPool, index, tag, width
String stringValue()
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.boolean equalsString(String s)
s - the string to compare toboolean isFieldType(ClassDesc desc)
desc - the field typeboolean isMethodType(MethodTypeDesc desc)
desc - the method type
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/classfile/constantpool/Utf8Entry.html