java.lang.Object
java.lang.constant.DynamicConstantDesc<T>
- 类型参数:
-
T- 动态常量的类型
- 所有实现的接口:
-
ConstantDesc
- 直接已知的子类:
-
Enum.EnumDesc,VarHandle.VarHandleDesc
一个用于动态常量的名义描述符(在常量池中用
Constant_Dynamic_info描述的常量)。
DynamicConstantDesc的具体子类型应该是不可变的,其行为不应依赖于对象标识。
- 自 JDK 版本:
- 12
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs) 创建一个动态常量的名义描述符。 -
Method Summary
Modifier and TypeMethodDescription返回此常量的引导参数。返回此常量的引导参数作为不可变的List。返回描述此常量的引导方法的MethodHandleDesc。返回此常量的LDC的NameAndType操作数中将出现的名称。final boolean将指定的对象与此描述符进行比较以检查是否相等。final inthashCode()返回对象的哈希码值。static <T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod) 返回一个动态常量的名义描述符,其引导没有静态参数,名称参数为ConstantDescs.DEFAULT_NAME,类型参数始终与引导方法的返回类型相同。static <T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod, ConstantDesc... bootstrapArgs) 返回一个动态常量的名义描述符,其名称参数为ConstantDescs.DEFAULT_NAME,类型参数始终与引导方法的返回类型相同。static <T> ConstantDescofCanonical(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc[] bootstrapArgs) 返回一个动态常量的名义描述符,如果常量引导是一个众所周知的引导,则将其转换为更具体的类型,如果更具体的名义描述符类型(例如ClassDesc)可用,则进行转换。static <T> DynamicConstantDesc<T> ofNamed(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs) 返回一个动态常量的名义描述符。toString()返回此常量描述的紧凑文本描述,包括引导方法、常量名称和类型以及静态引导参数。
-
Constructor Details
-
DynamicConstantDesc
protected DynamicConstantDesc(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs) 创建一个动态常量的名义描述符。- 参数:
-
bootstrapMethod- 描述常量的引导方法的DirectMethodHandleDesc -
constantName- 将出现在此常量的LDC的NameAndType操作数中的未限定名称 -
constantType- 描述将出现在此常量的LDC的NameAndType操作数中的类型的ClassDesc -
bootstrapArgs- 描述引导的静态参数的ConstantDesc,将出现在BootstrapMethods属性中 - 抛出:
-
NullPointerException- 如果任何参数为 null -
IllegalArgumentException- 如果name格式不正确 - 参见 Java 虚拟机规范:
-
4.2.2 未限定名称
-
-
Method Details
-
ofCanonical
public static <T> ConstantDesc ofCanonical(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc[] bootstrapArgs) 返回一个动态常量的名义描述符,如果常量引导是一个众所周知的引导,则将其转换为更具体的类型,如果更具体的名义描述符类型(例如ClassDesc)可用,则进行转换。其
Constable.describeConstable()方法生成一个包含众所周知引导的DynamicConstantDesc的类应该包括Class(用于描述原始类型的实例)、Enum和VarHandle。处理常量池并希望将条目作为
ConstantDesc公开给其调用者的字节码读取 API 应通常优先使用此方法,而不是使用ofNamed(DirectMethodHandleDesc, String, ClassDesc, ConstantDesc...),因为这可能会导致提供给调用者更具体的类型。- 类型参数:
-
T- 动态常量的类型 - 参数:
-
bootstrapMethod- 描述常量的引导方法的DirectMethodHandleDesc -
constantName- 将出现在此常量的LDC的NameAndType操作数中的未限定名称 -
constantType- 描述将出现在此常量的LDC的NameAndType操作数中的类型的ClassDesc -
bootstrapArgs- 描述引导的静态参数的ConstantDesc,将出现在BootstrapMethods属性中 - 返回:
- 名义描述符
- 抛出:
-
NullPointerException- 如果任何参数为 null -
IllegalArgumentException- 如果name格式不正确 - 参见 Java 虚拟机规范:
-
4.2.2 未限定名称
-
ofNamed
public static <T> DynamicConstantDesc<T> ofNamed(DirectMethodHandleDesc bootstrapMethod, String constantName, ClassDesc constantType, ConstantDesc... bootstrapArgs) 返回一个动态常量的名义描述符。- 类型参数:
-
T- 动态常量的类型 - 参数:
-
bootstrapMethod- 描述常量的引导方法的DirectMethodHandleDesc -
constantName- 将出现在此常量的LDC的NameAndType操作数中的未限定名称 -
constantType- 描述将出现在此常量的LDC的NameAndType操作数中的类型的ClassDesc -
bootstrapArgs- 描述引导的静态参数的ConstantDesc,将出现在BootstrapMethods属性中 - 返回:
- 名义描述符
- 抛出:
-
NullPointerException- 如果任何参数为 null -
IllegalArgumentException- 如果name格式不正确 - 参见 Java 虚拟机规范:
-
4.2.2 未限定名称
-
of
public static <T> DynamicConstantDesc<T> of(DirectMethodHandleDesc bootstrapMethod, ConstantDesc... bootstrapArgs) 返回一个动态常量的名义描述符,其名称参数为ConstantDescs.DEFAULT_NAME,类型参数始终与引导方法的返回类型相同。- 类型参数:
-
T- 动态常量的类型 - 参数:
-
bootstrapMethod- 描述常量的引导方法的DirectMethodHandleDesc -
bootstrapArgs- 描述引导的静态参数的ConstantDesc,将出现在BootstrapMethods属性中 - 返回:
- 名义描述符
- 抛出:
-
NullPointerException- 如果任何参数为 null - 参见 Java 虚拟机规范:
-
4.2.2 未限定名称
-
of
返回一个动态常量的名义描述符,其引导没有静态参数,名称参数为ConstantDescs.DEFAULT_NAME,类型参数始终与引导方法的返回类型相同。- 类型参数:
-
T- 动态常量的类型 - 参数:
-
bootstrapMethod- 描述常量的引导方法的DirectMethodHandleDesc - 返回:
- 名义描述符
- 抛出:
-
NullPointerException- 如果任何参数为null
-
constantName
返回将出现在此常量的NameAndType操作数中的名称。- 返回:
- 常量名称
-
constantType
返回描述将出现在此常量的NameAndType操作数中的类型的ClassDesc。- 返回:
- 常量类型
-
bootstrapMethod
返回描述此常量的引导方法的MethodHandleDesc。- 返回:
- 引导方法
-
bootstrapArgs
返回此常量的引导参数。- 返回:
- 引导参数
-
bootstrapArgsList
返回此常量的引导参数作为不可变的List。- 返回:
-
引导参数的
List
-
resolveConstantDesc
从接口复制的描述:ConstantDesc- 指定者:
-
resolveConstantDesc在接口ConstantDesc - 参数:
-
lookup- 提供名称解析和访问控制上下文的MethodHandles.Lookup - 返回:
- 已解析的常量值
- 抛出:
-
ReflectiveOperationException- 如果在解析过程中无法反射解析类、方法或字段
-
equals
将指定的对象与此描述符进行比较以确定是否相等。仅当指定的对象也是DynamicConstantDesc,并且两个描述符具有相等的引导方法、引导参数列表、常量名称和常量类型时,才返回true。 -
hashCode
public final int hashCode()从类复制的描述:Object返回此对象的哈希码值。此方法支持哈希表(如HashMap)的好处。hashCode的一般约定是:- 在Java应用程序的执行过程中,如果在同一对象上多次调用它,则
hashCode方法必须一致地返回相同的整数,前提是在对象上用于equals比较的信息未被修改。这个整数不需要在一个应用程序的执行到另一个应用程序的执行之间保持一致。 - 如果两个对象根据
equals方法是相等的,则在这两个对象的每个对象上调用hashCode方法必须产生相同的整数结果。 - 不要求如果两个对象根据
equals方法是不相等的,则在这两个对象的每个对象上调用hashCode方法必须产生不同的整数结果。但是,程序员应该意识到,为不相等的对象产生不同的整数结果可能会提高哈希表的性能。
- 在Java应用程序的执行过程中,如果在同一对象上多次调用它,则
-
toString
返回此常量描述的紧凑文本描述,包括引导方法、常量名称和类型以及静态引导参数。
-