Interface Constable


public interfaceConstable
Represents a type which isconstable. A constable type is one whosevalues are constants that can be represented in the constant pool of a Javaclassfile as described in JVMS4.4, and whose instances can describe themselvesnominally as aConstantDesc.

Some constable types have a native representation in the constant pool:String,Integer,Long,Float,Double,Class,MethodType, andMethodHandle.The typesString,Integer,Long,Float,andDouble serve as their own nominal descriptors;Class,MethodType, andMethodHandle have corresponding nominaldescriptorsClassDesc,MethodTypeDesc, andMethodHandleDesc.

Other reference types can be constable if their instances can describethemselves in nominal form as aConstantDesc. Examples in the Java SEPlatform API are types that support Java language features such asEnum,and runtime support classes such asVarHandle. These are typicallydescribed with aDynamicConstantDesc, which describes dynamicallygenerated constants (JVMS4.4.10).

The nominal form of an instance of a constable type is obtained viadescribeConstable(). AConstable neednot be able to (or may choose not to) describe all its instances in the form ofaConstantDesc; this method returns anOptional that can beempty to indicate that a nominal descriptor could not be created for an instance.(For example,MethodHandle will produce nominal descriptors for directmethod handles, but not necessarily those produced by method handlecombinators.)

SeeJava Virtual Machine Specification:
4.4 The Constant Pool
4.4.10 TheCONSTANT_Dynamic_info andCONSTANT_InvokeDynamic_info Structures
Since:
12
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns anOptional containing the nominal descriptor for thisinstance, if one can be constructed, or an emptyOptionalif one cannot be constructed.
  • Method Details

    • describeConstable

      Optional<? extendsConstantDesc> describeConstable()
      Returns anOptional containing the nominal descriptor for thisinstance, if one can be constructed, or an emptyOptionalif one cannot be constructed.
      Returns:
      AnOptional containing the resulting nominal descriptor,or an emptyOptional if one cannot be constructed.