Class ParameterizedType


  • public class ParameterizedType
    extends Type
    Represents a generic parameterized type. The name() corresponds to the raw type, and the arguments list corresponds to a list of type arguments passed to the parameterized type.

    Additionally, a parameterized type is used to represent an inner class whose enclosing class is either parameterized or has type annotations. In this case, the owner() method will specify the type for the enclosing class. It is also possible for such a type to be parameterized itself.

    For example, the follow declaration would have a name of "java.util.Map", and two ClassType arguments, the first being "java.lang.String", the second "java.lang.Integer":

         java.util.Map<String, Integer>
     

    Another example shows the case where a parameterized type is used to represent a non-parameterized class (X), whose owner (Y) is itself parameterized:

         Y<String>.X
     
    Since:
    2.0
    Author:
    Jason T. Greene
    • Method Detail

      • create

        public static ParameterizedType create​(DotName name,
                                               Type[] arguments,
                                               Type owner)
        Create a new mock instance.
        Parameters:
        name - the name of this type
        arguments - an array of types representing arguments to this type
        owner - the enclosing type if annotated or parameterized, otherwise null
        Returns:
        the mock instance
        Since:
        2.1
      • arguments

        public List<Type> arguments()
        Returns the list of arguments passed to this Parameterized type.
        Returns:
        the list of type arguments, or empty if none
      • owner

        public Type owner()
        Returns the owner (enclosing) type of this parameterized type if the owner is parameterized, or contains type annotations. The latter may be a ClassType. Otherwise null is returned.

        Note that this means that inner classes whose enclosing types are not parameterized or annotated may return null when this method is called.

        The example below shows the case where a parameterized type is used to represent a non-parameterized class (X).

             Y<String>.X
         

        This example will return a parameterized type for "Y" when X's owner() method is called.

        Returns:
        the owner type if the owner is parameterized or annotated, otherwise null
      • kind

        public Type.Kind kind()
        Description copied from class: Type
        Returns the kind of Type this is.
        Specified by:
        kind in class Type
        Returns:
        the kind
      • toString

        public String toString()
        Description copied from class: Type
        Returns a string representation for this type. It is similar, yet not equivalent to a Java source code representation.
        Overrides:
        toString in class Type
        Returns:
        the string representation.
      • equals

        public boolean equals​(Object o)
        Description copied from class: Type
        Compares this Type with another type, and returns true if they are equivalent. A type is equivalent to another type if it is the same kind, and all of its fields are equal. This includes annotations, which must be equal as well.
        Overrides:
        equals in class Type
        Parameters:
        o - the type to compare to
        Returns:
        true if equal
        See Also:
        Object.equals(Object)
      • hashCode

        public int hashCode()
        Description copied from class: Type
        Computes a hash code representing this type.
        Overrides:
        hashCode in class Type
        Returns:
        the hash code