Module jakarta.cdi

Interface Types


  • public interface Types
    Factory for types. Allows creating representations of the void pseudo-type, primitive types, class types, array types, parameterized types and wildcard types.
    Since:
    4.0
    • Method Detail

      • of

        Type of​(java.lang.Class<?> clazz)
        Returns a type from given class literal. For example:
        • of(void.class): same as ofVoid()
        • of(int.class): same as ofPrimitive(PrimitiveKind.INT)
        • of(String.class): same as ofClass(... ClassInfo for String ...)
        • of(int[].class): same as ofArray(ofPrimitive(PrimitiveKind.INT), 1)
        • of(String[][].class): same as ofArray(ofClass(... ClassInfo for String ...), 2)
        Parameters:
        clazz - the class literal, must not be null
        Returns:
        Type object representing the given class literal
      • ofClass

        ClassType ofClass​(java.lang.String name)
        Returns a ClassType for the given binary name, as defined by The Java™ Language Specification; in other words, the class name as returned by Class.getName().

        Note that this method returns ClassType, so name may only be a name of a class. For primitives, use ofPrimitive(PrimitiveType.PrimitiveKind). For arrays, use ofArray(Type, int).

        Parameters:
        name - the binary name of the class, must not be null
        Returns:
        the ClassType or null if the class is not present in any bean archive
      • ofArray

        ArrayType ofArray​(Type elementType,
                          int dimensions)
        Returns an ArrayType for the given element type and number of dimensions.

        Note that this method accepts the element type of an array, even though ArrayType uses a component type representation. For example, the component type of String[][] is String[], while the element type is String.

        Parameters:
        elementType - the element Type, must not be null
        dimensions - the number of dimensions
        Returns:
        the ArrayType, never null
        Throws:
        java.lang.IllegalArgumentException - if the element type is an array type, a wildcard type, or the void pseudo-type
      • parameterized

        ParameterizedType parameterized​(java.lang.Class<?> genericType,
                                        java.lang.Class<?>... typeArguments)
        Returns a ParameterizedType for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.
        Parameters:
        genericType - the type to parameterize, must not be null
        typeArguments - one or more type arguments
        Returns:
        the parameterized type, never null
        Throws:
        java.lang.IllegalArgumentException - if given genericType is not generic or if the number of type arguments does not match the number of type parameters declared by genericType
      • parameterized

        ParameterizedType parameterized​(java.lang.Class<?> genericType,
                                        Type... typeArguments)
        Returns a ParameterizedType for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.
        Parameters:
        genericType - the type to parameterize, must not be null
        typeArguments - one or more type arguments
        Returns:
        the parameterized type, never null
        Throws:
        java.lang.IllegalArgumentException - if given genericType is not generic or if the number of type arguments does not match the number of type parameters declared by genericType
      • parameterized

        ParameterizedType parameterized​(ClassType genericType,
                                        Type... typeArguments)
        Returns a ParameterizedType for the given generic type and type arguments. The array of type arguments must have the same shape as the generic type's list of type parameters.
        Parameters:
        genericType - the type to parameterize, must not be null
        typeArguments - one or more type arguments
        Returns:
        the parameterized type, never null
        Throws:
        java.lang.IllegalArgumentException - if given genericType is not generic or if the number of type arguments does not match the number of type parameters declared by genericType
      • wildcardWithUpperBound

        WildcardType wildcardWithUpperBound​(Type upperBound)
        Returns a WildcardType that represents an equivalent of ? extends upperBound. Note that if upperBound represents the java.lang.Object type, then the result is equivalent to wildcardUnbounded().
        Parameters:
        upperBound - upper bound type, must not be null
        Returns:
        a WildcardType object representing a wildcard type with given upper bound
      • wildcardWithLowerBound

        WildcardType wildcardWithLowerBound​(Type lowerBound)
        Returns a WildcardType that represents an equivalent of ? super lowerBound.
        Parameters:
        lowerBound - lower bound type, must not be null
        Returns:
        a WildcardType object representing a wildcard type with given upper bound
      • wildcardUnbounded

        WildcardType wildcardUnbounded()
        Returns a WildcardType that represents an equivalent of ?.
        Returns:
        a WildcardType object representing an unbounded wildcard type