Class Types

    • Method Detail

      • isArray

        public static boolean isArray​(Type input)
        Get if the provided type is an array type.

        Being an array type means that the provided type has a component type.

        Parameters:
        input - input type
        Returns:
        whether the type is an array
        Since:
        4.0.0
      • isBoxedPrimitive

        public static boolean isBoxedPrimitive​(Type input)
        Get whether or not the provided input type is a boxed primitive type.

        This check will not match unboxed primitives.

        Parameters:
        input - type to check
        Returns:
        if type is a boxed primitive
        Since:
        4.0.0
      • unbox

        public static Type unbox​(Type input)
        Unbox the input type if it is a boxed primitive.
        Parameters:
        input - input type
        Returns:
        the unboxed version of the input type, or the input type if it was already non-primitive
        Since:
        4.0.0
      • defaultValue

        public static @Nullable Object defaultValue​(Class<?> type)
        Get the default value for a type.

        For all reference types, this is null. For all primitive types, this is equivalent to their defined default value.

        Parameters:
        type - the type to get a default value for
        Returns:
        the default value, or null for reference types
        Since:
        4.1.0
      • box

        public static Type box​(Type input)
        Box the input type if it is an unboxed primitive Class.
        Parameters:
        input - input type
        Returns:
        the unboxed version of the input type, or the input type if it was already a primitive, or had no primitive equivalent
        Since:
        4.0.0
      • makeListType

        public static <T> TypeToken<List<T>> makeListType​(TypeToken<T> elementType)
        Given an element type, create a new list type.
        Type Parameters:
        T - type of element
        Parameters:
        elementType - type token representing the element type
        Returns:
        new list type token
        Since:
        4.0.0
      • combinedAnnotations

        public static AnnotatedElement combinedAnnotations​(AnnotatedElement... elements)
        Get an element containing the annotations of all the provided elements.

        If multiple elements have the same annotation, only the first one with an applicable type is returned.

        Parameters:
        elements - elements to combine
        Returns:
        new union element
        Since:
        4.0.0
      • requireCompleteParameters

        public static Type requireCompleteParameters​(Type input)
        Throw an exception if the passed type is raw (missing parameters)..
        Parameters:
        input - input type
        Returns:
        type, passed through
        Since:
        4.0.0
      • allSuperTypes

        public static Stream<TypeallSuperTypes​(Type type)
        Get all supertypes of this object with type parameters.

        The iteration order is undefined. The returned stream will include the base type plus superclasses, but not superinterfaces.

        Parameters:
        type - base type
        Returns:
        stream of supertypes
        Since:
        4.0.0
      • allSuperTypesAndInterfaces

        public static Stream<TypeallSuperTypesAndInterfaces​(Type type)
        Get all supertypes and interfaces of the provided type.

        The iteration order is undefined. The returned stream will include the base type plus superclasses and superinterfaces.

        Parameters:
        type - base type
        Returns:
        stream of supertypes
        Since:
        4.0.0