Interface Const

All Superinterfaces:
Constable, Expr, SimpleTyped, Typed

public sealed interface Const extends Expr, Constable
An expression which wraps a ConstantDesc.
  • Method Details

    • desc

      ConstantDesc desc()
      Returns the description of the constant.
      Returns:
      the description of the constant
    • of

      static Const of(Constable constable)
      Returns a constant for the given Constable.
      Parameters:
      constable - the object to create a constant from (must not be null)
      Returns:
      a constant for the given Constable
    • of

      static Const of(ConstantDesc constantDesc)
      Returns a constant for the given description.
      Parameters:
      constantDesc - the object to create a constant from (must not be null)
      Returns:
      a constant for the given description
    • of

      static Const of(DynamicConstantDesc<?> dcd)
      Returns a constant for the given description.
      Parameters:
      dcd - the object to create a constant from (must not be null)
      Returns:
      a constant for the given description
    • ofNull

      static Const ofNull(ClassDesc type)
      Returns a null constant with the given type.
      Parameters:
      type - the type of the null constant (used for inference of type) (must not be null)
      Returns:
      a null constant with the given type
    • ofNull

      static Const ofNull(Class<?> type)
      Returns a null constant with the given type.
      Parameters:
      type - the type of the null constant (used for inference of type) (must not be null)
      Returns:
      a null constant with the given type
    • ofDefault

      static Const ofDefault(ClassDesc type)
      Returns a constant with the default value of given type. This is zero for primitive types and null for reference types.
      Parameters:
      type - the type of the constant (must not be null)
      Returns:
      a constant with the default value of given type
    • ofDefault

      static Const ofDefault(Class<?> type)
      Returns a constant with the default value of given type. This is zero for primitive types and null for reference types.
      Parameters:
      type - the type of the constant (must not be null)
      Returns:
      a constant with the default value of given type
    • of

      static Const of(ClassDesc value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(Class<?> value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(VarHandle.VarHandleDesc value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(Enum.EnumDesc<?> value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(Byte value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(byte value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Short value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(short value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Character value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(char value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Integer value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(int value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Long value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(long value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Float value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(float value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Double value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(double value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(Boolean value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(boolean value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      Returns:
      a constant for the given value
    • of

      static Const of(int value, TypeKind typeKind)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      typeKind - the (numeric) kind of value to use for inference (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(long value, TypeKind typeKind)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      typeKind - the (numeric) kind of value to use for inference (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(float value, TypeKind typeKind)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      typeKind - the (numeric) kind of value to use for inference (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(double value, TypeKind typeKind)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from
      typeKind - the (numeric) kind of value to use for inference (must not be null)
      Returns:
      a constant for the given value
    • of

      static Const of(String value)
      Returns a constant for the given value.
      Parameters:
      value - the value to create a constant from (must not be null)
      Returns:
      a constant for the given value
    • ofVoid

      static Const ofVoid()
      Returns the void constant.
      Returns:
      the void constant
    • ofFieldVarHandle

      static Const ofFieldVarHandle(FieldDesc desc)
      Returns a VarHandle constant for the given instance field.
      Parameters:
      desc - the descriptor of the field (must not be null)
      Returns:
      a VarHandle constant for the given instance field
    • ofStaticFieldVarHandle

      static Const ofStaticFieldVarHandle(FieldDesc desc)
      Returns a VarHandle constant for the given static field.
      Parameters:
      desc - the descriptor of the field (must not be null)
      Returns:
      a VarHandle constant for the given static field
    • ofStaticFinalField

      static Const ofStaticFinalField(FieldDesc desc)
      Returns a constant with the value of the given static final field.
      Parameters:
      desc - the descriptor of the field (must not be null)
      Returns:
      a constant with the value of the given static final field
    • ofArrayVarHandle

      static Const ofArrayVarHandle(ClassDesc arrayType)
      Returns a VarHandle constant for the given array type.
      Parameters:
      arrayType - the array type (must not be null)
      Returns:
      a VarHandle constant for the given array type
    • ofInvoke

      static Const ofInvoke(Const methodHandle, List<Const> args)
      Returns a constant whose value is the result of a one-time method invocation. Note that due to the nature of dynamic constants, parallel threads may cause the method to be invoked more than once.
      Parameters:
      methodHandle - the method handle to invoke (must not be null)
      args - the list of arguments (must not be null)
      Returns:
      a constant whose value is the result of a one-time method invocation
    • ofInvoke

      static Const ofInvoke(Const methodHandle, Const... args)
      Returns a constant whose value is the result of a one-time method invocation. Note that due to the nature of dynamic constants, parallel threads may cause the method to be invoked more than once.
      Parameters:
      methodHandle - the method handle to invoke (must not be null)
      args - the list of arguments (must not be null)
      Returns:
      a constant whose value is the result of a one-time method invocation
    • of

      static Const of(MethodHandleDesc desc)
      Returns a method handle constant from the given descriptor.
      Parameters:
      desc - the method handle descriptor (must not be null)
      Returns:
      a method handle constant from the given descriptor
    • ofMethodHandle

      static Const ofMethodHandle(InvokeKind kind, MethodDesc desc)
      Returns a method handle constant from the given information.
      Parameters:
      kind - the invocation kind (must not be null)
      desc - the method's descriptor (must not be null)
      Returns:
      a method handle constant from the given information
    • ofConstructorMethodHandle

      static Const ofConstructorMethodHandle(ConstructorDesc desc)
      Returns a method handle constant from the given constructor descriptor.
      Parameters:
      desc - the constructor descriptor (must not be null)
      Returns:
      a method handle constant from the given constructor descriptor
    • ofFieldSetterMethodHandle

      static Const ofFieldSetterMethodHandle(FieldDesc desc)
      Returns a method handle for an instance field setter.
      Parameters:
      desc - the field descriptor (must not be null)
      Returns:
      a method handle for an instance field setter
    • ofFieldGetterMethodHandle

      static Const ofFieldGetterMethodHandle(FieldDesc desc)
      Returns a method handle for an instance field getter.
      Parameters:
      desc - the field descriptor (must not be null)
      Returns:
      a method handle for an instance field getter
    • ofStaticFieldSetterMethodHandle

      static Const ofStaticFieldSetterMethodHandle(FieldDesc desc)
      Returns a method handle for a static field setter.
      Parameters:
      desc - the field descriptor (must not be null)
      Returns:
      a method handle for a static field setter
    • ofStaticFieldGetterMethodHandle

      static Const ofStaticFieldGetterMethodHandle(FieldDesc desc)
      Returns a method handle for a static field getter.
      Parameters:
      desc - the field descriptor (must not be null)
      Returns:
      a method handle for a static field getter
    • of

      static Const of(MethodTypeDesc desc)
      Returns a method type constant from the given descriptor.
      Parameters:
      desc - the method type descriptor (must not be null)
      Returns:
      a method type constant from the given descriptor
    • of

      static Const of(List<?> items)
      Returns a list constant containing the given items. The maximum number of items is around 254 (depending on the constant type); however, this method should only be used for relatively short lists to avoid overfilling the constant pool. Note that the JDK immutable collection types forbid null, so null values should not be used.
      Parameters:
      items - the list of items, which must be Const, Constable, or ConstantDesc subtypes (must not be null)
      Returns:
      a list constant containing the given items
    • of

      static Const of(Set<?> items)
      Returns a set constant containing the given items. The maximum number of items is around 254 (depending on the constant type); however, this method should only be used for relatively small sets to avoid overfilling the constant pool. Note that the JDK immutable collection types forbid null, so null values should not be used.
      Parameters:
      items - the set of items, which must be Const, Constable, or ConstantDesc subtypes (must not be null)
      Returns:
      a set constant containing the given items
    • of

      static Const of(Map<?,?> items)
      Returns a map constant containing the given items. The maximum number of items is around 254 (depending on the constant type); however, this method should only be used for relatively small maps to avoid overfilling the constant pool. Note that the JDK immutable collection types forbid null, so null values should not be used.
      Parameters:
      items - the set of items, which must be Const, Constable, or ConstantDesc subtypes (must not be null)
      Returns:
      a map constant containing the given items
    • of

      static Const of(Map.Entry<?,?> entry)
      Returns a map entry constant with the key and value of the given entry.
      Parameters:
      entry - the map entry containing a constant key and value, which must be Const, Constable, or ConstantDesc subtypes (must not be null)
      Returns:
      a map entry constant with the key and value of the given entry