Class Types


  • public final class Types
    extends java.lang.Object
    Static methods for working with types.
    Since:
    2.0
    • Method Summary

      Modifier and Type Method Description
      static java.lang.reflect.GenericArrayType arrayOf​(java.lang.reflect.Type componentType)
      Returns an array type whose elements are all instances of componentType.
      static java.lang.reflect.ParameterizedType listOf​(java.lang.reflect.Type elementType)
      Returns a type modelling a List whose elements are of type elementType.
      static java.lang.reflect.ParameterizedType mapOf​(java.lang.reflect.Type keyType, java.lang.reflect.Type valueType)
      Returns a type modelling a Map whose keys are of type keyType and whose values are of type valueType.
      static java.lang.reflect.ParameterizedType newParameterizedType​(java.lang.reflect.Type rawType, java.lang.reflect.Type... typeArguments)
      Returns a new parameterized type, applying typeArguments to rawType.
      static java.lang.reflect.ParameterizedType newParameterizedTypeWithOwner​(java.lang.reflect.Type ownerType, java.lang.reflect.Type rawType, java.lang.reflect.Type... typeArguments)
      Returns a new parameterized type, applying typeArguments to rawType and enclosed by ownerType.
      static java.lang.reflect.ParameterizedType providerOf​(java.lang.reflect.Type providedType)
      Returns a type modelling a Provider that provides elements of type elementType.
      static java.lang.reflect.ParameterizedType setOf​(java.lang.reflect.Type elementType)
      Returns a type modelling a Set whose elements are of type elementType.
      static java.lang.reflect.WildcardType subtypeOf​(java.lang.reflect.Type bound)
      Returns a type that represents an unknown type that extends bound.
      static java.lang.reflect.WildcardType supertypeOf​(java.lang.reflect.Type bound)
      Returns a type that represents an unknown supertype of bound.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • newParameterizedType

        public static java.lang.reflect.ParameterizedType newParameterizedType​(java.lang.reflect.Type rawType,
                                                                               java.lang.reflect.Type... typeArguments)
        Returns a new parameterized type, applying typeArguments to rawType. The returned type does not have an owner type.
        Returns:
        a parameterized type.
      • newParameterizedTypeWithOwner

        public static java.lang.reflect.ParameterizedType newParameterizedTypeWithOwner​(java.lang.reflect.Type ownerType,
                                                                                        java.lang.reflect.Type rawType,
                                                                                        java.lang.reflect.Type... typeArguments)
        Returns a new parameterized type, applying typeArguments to rawType and enclosed by ownerType.
        Returns:
        a parameterized type.
      • arrayOf

        public static java.lang.reflect.GenericArrayType arrayOf​(java.lang.reflect.Type componentType)
        Returns an array type whose elements are all instances of componentType.
        Returns:
        a generic array type.
      • subtypeOf

        public static java.lang.reflect.WildcardType subtypeOf​(java.lang.reflect.Type bound)
        Returns a type that represents an unknown type that extends bound. For example, if bound is CharSequence.class, this returns ? extends CharSequence. If bound is Object.class, this returns ?, which is shorthand for ? extends Object.
      • supertypeOf

        public static java.lang.reflect.WildcardType supertypeOf​(java.lang.reflect.Type bound)
        Returns a type that represents an unknown supertype of bound. For example, if bound is String.class, this returns ? super String.
      • listOf

        public static java.lang.reflect.ParameterizedType listOf​(java.lang.reflect.Type elementType)
        Returns a type modelling a List whose elements are of type elementType.
        Returns:
        a parameterized type.
      • setOf

        public static java.lang.reflect.ParameterizedType setOf​(java.lang.reflect.Type elementType)
        Returns a type modelling a Set whose elements are of type elementType.
        Returns:
        a parameterized type.
      • mapOf

        public static java.lang.reflect.ParameterizedType mapOf​(java.lang.reflect.Type keyType,
                                                                java.lang.reflect.Type valueType)
        Returns a type modelling a Map whose keys are of type keyType and whose values are of type valueType.
        Returns:
        a parameterized type.
      • providerOf

        public static java.lang.reflect.ParameterizedType providerOf​(java.lang.reflect.Type providedType)
        Returns a type modelling a Provider that provides elements of type elementType.
        Returns:
        a parameterized type.