Class ReifiedType

java.lang.Object
space.arim.dazzleconf.reflect.ReifiedType
Direct Known Subclasses:
ReifiedType.Annotated

public class ReifiedType extends Object
A possibly generic type, with its arguments fully specified.

This type is a runtime stand-in for fully reified generic information. Given that Java discards generic type data at runtime, this type exists to retain that data. Lastly, while this class itself contains the raw generic data, it is designed for low-level usage. See TypeToken for an ergonomic high-level version.

This class should be considered sealed and not subclassed. Equality is defined for any two reified types based on whether the raw type and arguments match, or annotations if ReifiedType.Annotated is used.

This class and its subtype ReifiedType.Annotated are both immutable.

  • Constructor Details

    • ReifiedType

      public ReifiedType(@NonNull Class<?> rawType, @NonNull ReifiedType @NonNull [] arguments)
      Builds from nonnull input arguments.
      Parameters:
      rawType - the raw type
      arguments - the arguments, which are copied to ensure immutability
  • Method Details

    • rawType

      public @NonNull Class<?> rawType()
      Gets the raw type, unparameterized
      Returns:
      the raw type
    • argumentAt

      public @NonNull ReifiedType argumentAt(int index)
      Gets the argument at a certain index
      Parameters:
      index - the index
      Returns:
      the argument at it
      Throws:
      IndexOutOfBoundsException - if the index is out of range
    • argumentCount

      public int argumentCount()
      The argument count
      Returns:
      the argument count
    • arguments

      public @NonNull ReifiedType @NonNull [] arguments()
      Gets all the arguments
      Returns:
      a copy of the arguments
    • equals

      public final boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public final String toString()
      Overrides:
      toString in class Object