模块 java.base

类 DynamicConstantDesc<T>

java.lang.Object
java.lang.constant.DynamicConstantDesc<T>
类型参数:
T - 动态常量的类型
所有已实现的接口:
ConstantDesc
已知子类:
Enum.EnumDesc , VarHandle.VarHandleDesc

public abstract non-sealed class DynamicConstantDesc<T> extends Object implements ConstantDesc
一个 名义描述符 用于动态常量(一个在常量池中用 Constant_Dynamic_info 描述的。)

DynamicConstantDesc 的具体子类型应该是不可变的,它们的行为不应该依赖于对象标识。

自从:
12
  • 构造方法详细信息

  • 方法详情

    • 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 - 将出现在该常量的 LDCNameAndType 操作数中的非限定名称
      constantType - 一个 ClassDesc 描述将出现在该常量的 LDCNameAndType 操作数中的类型
      bootstrapArgs - ConstantDesc 描述引导程序的静态参数,将出现在 BootstrapMethods 属性中
      返回:
      名义描述符
      抛出:
      NullPointerException - 如果任何参数为空
      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 - 将出现在该常量的 LDCNameAndType 操作数中的非限定名称
      constantType - 一个 ClassDesc 描述将出现在该常量的 LDCNameAndType 操作数中的类型
      bootstrapArgs - ConstantDesc 描述引导程序的静态参数,将出现在 BootstrapMethods 属性中
      返回:
      名义描述符
      抛出:
      NullPointerException - 如果任何参数为空
      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 - 如果任何参数为空
      Java 虚拟机规范:
      4.2.2 非限定名称
    • of

      public static <T> DynamicConstantDesc <T> of(DirectMethodHandleDesc  bootstrapMethod)
      返回动态常量的标称描述符,其引导程序没有静态参数,名称参数为 ConstantDescs.DEFAULT_NAME ,并且其类型参数始终与引导程序方法返回类型相同。
      类型参数:
      T - 动态常量的类型
      参数:
      bootstrapMethod - 一个 DirectMethodHandleDesc 描述常量的引导方法
      返回:
      名义描述符
      抛出:
      NullPointerException - 如果任何参数为空
    • constantName

      public String  constantName()
      返回将出现在该常量的 LDCNameAndType 操作数中的名称。
      返回:
      常量名称
    • constantType

      public ClassDesc  constantType()
      返回一个 ClassDesc 描述将出现在该常量的 LDCNameAndType 操作数中的类型。
      返回:
      常量类型
    • bootstrapMethod

      public DirectMethodHandleDesc  bootstrapMethod()
      返回一个 MethodHandleDesc 描述这个常量的引导方法。
      返回:
      自举法
    • bootstrapArgs

      public ConstantDesc [] bootstrapArgs()
      返回此常量的引导程序参数。
      返回:
      引导参数
    • bootstrapArgsList

      public List <ConstantDesc > bootstrapArgsList()
      将此常量的引导程序参数作为不可变的 List 返回。
      返回:
      引导程序参数的 List
    • resolveConstantDesc

      public T  resolveConstantDesc(MethodHandles.Lookup  lookup) throws ReflectiveOperationException
      从接口 ConstantDesc 复制的描述
      反射地解析此描述符,模拟 JVMS 5.4.3 的解析行为和 JVMS 5.4.4 的访问控制行为。解析和访问控制上下文由 MethodHandles.Lookup 参数提供。不执行结果值的缓存。
      指定者:
      resolveConstantDesc 在接口 ConstantDesc
      参数:
      lookup - MethodHandles.Lookup 提供名称解析和访问控制上下文
      返回:
      解析的常量值
      抛出:
      ReflectiveOperationException - 如果类、方法或字段在解析过程中无法反射解析
    • equals

      public final boolean equals(Object  o)
      比较指定对象与此描述符是否相等。当且仅当指定对象也是 DynamicConstantDesc 并且两个描述符具有相同的引导方法、引导参数列表、常量名称和常量类型时返回 true
      重写:
      equals 在类 Object
      参数:
      o - 与这个 DynamicConstantDesc 比较的 DynamicConstantDesc
      返回:
      true 如果指定的 DynamicConstantDesc 等于此 DynamicConstantDesc
      参见:
    • hashCode

      public final int hashCode()
      从类复制的描述:Object
      返回对象的哈希码值。支持此方法是为了哈希表的好处,例如 HashMap 提供的哈希表。

      hashCode的总合同为:

      • 每当在 Java 应用程序的执行期间对同一个对象多次调用时,hashCode 方法必须始终返回相同的整数,前提是在对象的equals 比较中使用的信息没有被修改。从一个应用程序的一次执行到同一应用程序的另一次执行,该整数不需要保持一致。
      • 如果根据 equals 方法两个对象相等,则对这两个对象中的每一个调用 hashCode 方法必须产生相同的整数结果。
      • not 要求如果根据 equals 方法两个对象不相等,则对这两个对象中的每一个调用 hashCode 方法必须产生不同的整数结果。但是,程序员应该意识到,为不相等的对象生成不同的整数结果可能会提高哈希表的性能。
      重写:
      hashCode 在类 Object
      返回:
      此对象的哈希码值。
      参见:
    • toString

      public String  toString()
      返回此常量描述的紧凑文本描述,包括引导方法、常量名称和类型以及静态引导参数。
      重写:
      toString 在类 Object
      返回:
      此调用站点描述符的紧凑文本描述