Class JavaConstant.Simple<T>

java.lang.Object
net.bytebuddy.utility.JavaConstant.Simple<T>
Type Parameters:
T - The represented type.
All Implemented Interfaces:
ConstantValue, JavaConstant
Direct Known Subclasses:
JavaConstant.Simple.OfTrivialValue, JavaConstant.Simple.OfTypeDescription
Enclosing interface:
JavaConstant

public abstract static class JavaConstant.Simple<T> extends Object implements JavaConstant
Represents a simple Java constant, either a primitive constant, a String or a Class.
  • Field Details

  • Constructor Details

    • Simple

      protected Simple(T value, TypeDescription typeDescription)
      Creates a simple Java constant.
      Parameters:
      value - The represented constant pool value.
      typeDescription - A description of the type of the constant.
  • Method Details

    • doPrivileged

      @Enhance private static <T> T doPrivileged(PrivilegedAction<T> action)
      A proxy for java.security.AccessController#doPrivileged that is activated if available.
      Type Parameters:
      T - The type of the action's resolved value.
      Parameters:
      action - The action to execute from a privileged context.
      Returns:
      The action's resolved value.
    • ofLoaded

      public static JavaConstant ofLoaded(Object value)
      Resolves a loaded Java value to a Java constant representation.
      Parameters:
      value - The value to represent.
      Returns:
      An appropriate Java constant representation.
    • ofLoadedOrNull

      @MaybeNull protected static JavaConstant ofLoadedOrNull(Object value)
      Resolves a loaded Java value to a Java constant representation.
      Parameters:
      value - The value to represent.
      Returns:
      An appropriate Java constant representation or null if the supplied argument is not a compile-time constant.
    • ofDescription

      public static JavaConstant ofDescription(Object value, @MaybeNull ClassLoader classLoader)
      Creates a Java constant value from a java.lang.constant.ConstantDesc.
      Parameters:
      value - The java.lang.constant.ConstantDesc to represent.
      classLoader - The class loader to use for resolving type information from the supplied value.
      Returns:
      An appropriate Java constant representation.
    • ofDescription

      public static JavaConstant ofDescription(Object value, ClassFileLocator classFileLocator)
      Creates a Java constant value from a java.lang.constant.ConstantDesc.
      Parameters:
      value - The java.lang.constant.ConstantDesc to represent.
      classFileLocator - The class file locator to use for resolving type information from the supplied value.
      Returns:
      An appropriate Java constant representation.
    • ofDescription

      public static JavaConstant ofDescription(Object value, TypePool typePool)
      Creates a Java constant value from a java.lang.constant.ConstantDesc.
      Parameters:
      value - The java.lang.constant.ConstantDesc to represent.
      typePool - The type pool to use for resolving type information from the supplied value.
      Returns:
      An appropriate Java constant representation.
    • of

      public static JavaConstant of(TypeDescription typeDescription)
      Returns a Java constant representation for a TypeDescription.
      Parameters:
      typeDescription - The type to represent as a constant.
      Returns:
      An appropriate Java constant representation.
    • wrap

      public static JavaConstant wrap(Object value)
      Wraps a value representing a loaded or unloaded constant as JavaConstant instance.
      Parameters:
      value - The value to wrap.
      Returns:
      A wrapped Java constant.
    • wrap

      public static List<JavaConstant> wrap(List<?> values)
      Wraps a list of either loaded or unloaded constant representations as JavaConstant instances.
      Parameters:
      values - The values to wrap.
      Returns:
      A list of wrapped Java constants.
    • getValue

      public T getValue()
      Returns the represented value.
      Returns:
      The represented value.
    • getTypeDescription

      public TypeDescription getTypeDescription()
      Returns a description of the type of this constant.
      Specified by:
      getTypeDescription in interface ConstantValue
      Returns:
      A description of the type of this constant.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(@MaybeNull Object object)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object