Package com.tngtech.archunit.core.domain
Class JavaWildcardType
java.lang.Object
com.tngtech.archunit.core.domain.JavaWildcardType
- All Implemented Interfaces:
JavaType,HasName,HasUpperBounds
@PublicAPI(usage=ACCESS)
public final class JavaWildcardType
extends Object
implements JavaType, HasUpperBounds
Represents a wildcard type in a type signature (compare the JLS).
Consider the generic type
According to the JLS a wildcard may have upper and lower bounds.
An upper bound denotes a common supertype any substitution of this wildcard must be assignable to. It is denoted by
A lower bound denotes a common subtype that must be assignable to all substitutions of this wildcard type. It is denoted by
List<T>, then the parameterized type
List<?> would have the wildcard ? as its type argument
(also see JavaParameterizedType).According to the JLS a wildcard may have upper and lower bounds.
An upper bound denotes a common supertype any substitution of this wildcard must be assignable to. It is denoted by
? extends SomeType.A lower bound denotes a common subtype that must be assignable to all substitutions of this wildcard type. It is denoted by
? super SomeType.-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.properties.HasName
HasName.AndFullName, HasName.Predicates, HasName.UtilsNested classes/interfaces inherited from interface com.tngtech.archunit.core.domain.JavaType
JavaType.Functions -
Method Summary
Modifier and TypeMethodDescriptionReturns the set of all raw types that are involved in this type.getName()Converts thisJavaTypeinto the erased type (compare the Java Language Specification).toString()
-
Method Details
-
getName
- Specified by:
getNamein interfaceHasName- Returns:
- The name of this
JavaWildcardType, which is always "?", followed by the respective bounds if any are present (e.g. "? extends java.lang.String")
-
getUpperBounds
- Specified by:
getUpperBoundsin interfaceHasUpperBounds- Returns:
- All upper bounds of this
JavaWildcardType, i.e. supertypes any substitution of this variable must extend. E.g. forList<? extends SomeClass>the upper bounds would be[SomeClass]
Note that the JLS currently only allows a single upper bound for a wildcard type, but we follow the Reflection API here and support a collection (compareWildcardType.getUpperBounds()).
-
getLowerBounds
- Returns:
- All lower bounds of this
JavaWildcardType, i.e. any substitution for thisJavaWildcardTypemust be a supertype of all lower bounds. E.g. forHandler<? super SomeClass>>the lower bounds would be[SomeClass].
Note that the JLS currently only allows a single lower bound for a wildcard type, but we follow the Reflection API here and support a collection (compareWildcardType.getLowerBounds()).
-
toErasure
Description copied from interface:JavaTypeConverts thisJavaTypeinto the erased type (compare the Java Language Specification). In particular this will result in- the class itself, if this type is a
JavaClass - the
JavaClassequivalent toObject, if this type is an unboundJavaTypeVariable - the
JavaClassequivalent to the erasure of the left most bound, if this type is a boundJavaTypeVariable - if this type is a
JavaGenericArrayType, the erasure will be theJavaClassequivalent 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 typeT[][]whereTis unbound, then the erasure will be the array typeObject[][]
- the class itself, if this type is a
-
getAllInvolvedRawTypes
Description copied from interface:JavaTypeReturns the set of all raw types that are involved in this type. If this type is aJavaClass, then this method trivially returns only the class itself. If this type is aJavaParameterizedType,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
the result would be theList<String>classes[List, String].
For the parameterized type
the result would beMap<? extends Serializable, List<? super Integer[]>>[Map, Serializable, List, Integer].
And for the type variable
the result would beT extends List<? super Integer>[List, Integer].
Thus, this method offers a quick way to determine all types a (possibly complex) type depends on.- Specified by:
getAllInvolvedRawTypesin interfaceJavaType- Returns:
- All raw types involved in this
JavaType
-
toString
-