Interface Type


public interface Type
Describes a class which is being made, or describes an existing class or primitive type.
  • Method Summary

    Modifier and Type
    Method
    Description
    addAnnotation(Object annotationType, boolean visible)
    Add an annotation to this type, if it's annotatable.
    Returns a new type instance which supports annotations.
    Returns this type as an array, or else adds a dimension if this type is already an array.
    box()
    Returns an object type for a primitive type, or else returns this type.
    Returns the Class corresponding to this type, or else null if this type represents a class which is being made.
    Returns a descriptor string for this type.
    int
    Returns the dimensions of this array type, or else 0 if this type isn't an array.
    Returns the element type of this array type, or else null if this type isn't an array.
    void
    Prevent adding more annotations to this type.
    static Type
    from(Class<?> clazz)
    Return a Type corresponding to the given Class.
    static Type
    from(Object obj)
    Return a Type corresponding to the given object parameter.
    static Type
    from(Object obj, ClassLoader loader)
    Return a Type corresponding to the given object parameter, as found by the given ClassLoader.
    static Type
    from(String str)
    Return a Type corresponding to the given class name or type descriptor.
    static Type
    from(String str, ClassLoader loader)
    Return a Type corresponding to the given class name or type descriptor, as found by the given ClassLoader.
    boolean
    Returns true if this type is an array.
    boolean
    Returns true if this type is known to be an interface.
    boolean
    Returns true if this type is an array, an interface, or a class.
    boolean
    Returns true if this type is an int, boolean, double, etc.
    Returns the name of this type in Java syntax.
    Returns this type without any annotations.
    Returns a primitive type for an object type, or else returns null if not applicable.
  • Method Details

    • from

      static Type from(Class<?> clazz)
      Return a Type corresponding to the given Class.
    • from

      static Type from(String str)
      Return a Type corresponding to the given class name or type descriptor.
      Parameters:
      str - class name or type descriptor
    • from

      static Type from(String str, ClassLoader loader)
      Return a Type corresponding to the given class name or type descriptor, as found by the given ClassLoader.
      Parameters:
      str - class name or type descriptor
      loader - can be null to use the bootstrap ClassLoader
    • from

      static Type from(Object obj)
      Return a Type corresponding to the given object parameter.
      Parameters:
      obj - Class, String, ClassMaker, Variable, Field, FieldMaker, or ClassDesc
    • from

      static Type from(Object obj, ClassLoader loader)
      Return a Type corresponding to the given object parameter, as found by the given ClassLoader.
      Parameters:
      obj - Class, String, ClassMaker, Variable, Field, FieldMaker, or ClassDesc
      loader - can be null to use the bootstrap ClassLoader
    • name

      String name()
      Returns the name of this type in Java syntax.
    • descriptor

      String descriptor()
      Returns a descriptor string for this type.
    • classType

      Class<?> classType()
      Returns the Class corresponding to this type, or else null if this type represents a class which is being made.
    • isPrimitive

      boolean isPrimitive()
      Returns true if this type is an int, boolean, double, etc.
    • isObject

      boolean isObject()
      Returns true if this type is an array, an interface, or a class.
    • isInterface

      boolean isInterface()
      Returns true if this type is known to be an interface.
    • isArray

      boolean isArray()
      Returns true if this type is an array.
    • elementType

      Type elementType()
      Returns the element type of this array type, or else null if this type isn't an array.
    • dimensions

      int dimensions()
      Returns the dimensions of this array type, or else 0 if this type isn't an array.
    • asArray

      Type asArray()
      Returns this type as an array, or else adds a dimension if this type is already an array. If this type is annotatable, then the returned instance will also be annotatable, but it won't initially have any annotations.
    • box

      Type box()
      Returns an object type for a primitive type, or else returns this type. If this type is annotatable, then the returned instance will also be annotatable, and it will have a copy of all the annotations added so far.
    • unbox

      Type unbox()
      Returns a primitive type for an object type, or else returns null if not applicable. If this type is annotatable, then the returned instance will also be annotatable, and it will have a copy of all the annotations added so far.
    • annotatable

      Type annotatable()
      Returns a new type instance which supports annotations. If this type is already annotatable, then the new instance will have a copy of all the annotations added so far.

      Note: The hashCode and equals methods ignore annotations because annotations don't affect linkage rules.

    • addAnnotation

      AnnotationMaker addAnnotation(Object annotationType, boolean visible)
      Add an annotation to this type, if it's annotatable. Once this type has been used, it becomes frozen and no more annotations can be added. Instead, call the annotatable method to obtain a new instance.
      Parameters:
      annotationType - name or class which refers to an annotation interface
      visible - true if annotation is visible at runtime
      Throws:
      IllegalStateException - if this type isn't annotatable or it's frozen
      IllegalArgumentException - if the annotation type is unsupported
    • freeze

      void freeze()
      Prevent adding more annotations to this type.
    • unannotated

      Type unannotated()
      Returns this type without any annotations.