Class JavaTypeVariable<OWNER extends HasDescription>

java.lang.Object
com.tngtech.archunit.core.domain.JavaTypeVariable<OWNER>
All Implemented Interfaces:
JavaType, HasName, HasOwner<OWNER>, HasUpperBounds

@PublicAPI(usage=ACCESS) public final class JavaTypeVariable<OWNER extends HasDescription> extends Object implements JavaType, HasOwner<OWNER>, HasUpperBounds
Represents a type variable used by generic types and members.
E.g. class MyClass<T> would have one JavaTypeVariable with name "T" and unbound, i.e. only bound by Object.
A type variable can have several bounds, where only one bound may be a class bound while all further bounds must be interfaces (compare the JLS).
Example: class MyClass<T extends SomeClass & SomeInterfaceOne & SomeInterfaceTwo> would declare one JavaTypeVariable T which is bound by SomeClass, SomeInterfaceOne and SomeInterfaceTwo. I.e. any concrete class substituted for the type variable must extend SomeClass and implement SomeInterfaceOne and SomeInterfaceTwo.
  • Method Details

    • getName

      @PublicAPI(usage=ACCESS) public String getName()
      Specified by:
      getName in interface HasName
      Returns:
      The name of this JavaTypeVariable, e.g. for class MyClass<T> the name would be "T"
    • getGenericDeclaration

      @PublicAPI(usage=ACCESS) public OWNER getGenericDeclaration()
      This method is simply an alias for getOwner() that is more familiar to users of the Java Reflection API.
      See Also:
    • getOwner

      public OWNER getOwner()
      Specified by:
      getOwner in interface HasOwner<OWNER extends HasDescription>
      Returns:
      The 'owner' of this type parameter, i.e. the Java object that declared this TypeVariable as a type parameter. For type parameter T of SomeClass<T> this would be the JavaClass representing SomeClass
    • getBounds

      @PublicAPI(usage=ACCESS) public List<JavaType> getBounds()
      This method is simply an alias for getUpperBounds() that is more familiar to users of the Java Reflection API.
      See Also:
    • getUpperBounds

      @PublicAPI(usage=ACCESS) public List<JavaType> getUpperBounds()
      Specified by:
      getUpperBounds in interface HasUpperBounds
      Returns:
      All upper bounds of this JavaTypeVariable, i.e. super types any substitution of this variable must extend. E.g. for class MyClass<T extends SomeClass & SomeInterface> the upper bounds would be SomeClass and SomeInterface
    • toErasure

      @PublicAPI(usage=ACCESS) public JavaClass toErasure()
      Description copied from interface: JavaType
      Converts this JavaType into the erased type (compare the Java Language Specification). In particular this will result in
      • the class itself, if this type is a JavaClass
      • the JavaClass equivalent to Object, if this type is an unbound JavaTypeVariable
      • the JavaClass equivalent to the erasure of the left most bound, if this type is a bound JavaTypeVariable
      • if this type is a JavaGenericArrayType, the erasure will be the JavaClass equivalent to the array type that has the erasure of the generic component type of this type as its component type; e.g. take the generic array type T[][] where T is unbound, then the erasure will be the array type Object[][]
      Specified by:
      toErasure in interface JavaType
    • getAllInvolvedRawTypes

      public Set<JavaClass> getAllInvolvedRawTypes()
      Description copied from interface: JavaType
      Returns the set of all raw types that are involved in this type. If this type is a JavaClass, then this method trivially returns only the class itself. If this type is a JavaParameterizedType, JavaTypeVariable, JavaWildcardType, etc., then this method returns all raw types involved in type arguments and upper and lower bounds recursively. If this type is an array type, then this method returns all raw types involved in the component type of the array type.

      Examples:
      For the parameterized type
      
       List<String>
      the result would be the classes [List, String].
      For the parameterized type
      
       Map<? extends Serializable, List<? super Integer[]>>
      the result would be [Map, Serializable, List, Integer].
      And for the type variable
      
       T extends List<? super Integer>
      the result would be [List, Integer].
      Thus, this method offers a quick way to determine all types a (possibly complex) type depends on.
      Specified by:
      getAllInvolvedRawTypes in interface JavaType
      Returns:
      All raw types involved in this JavaType
    • toString

      public String toString()
      Overrides:
      toString in class Object