Class TypeUtils
java.lang.Object
io.smallrye.reactive.messaging.providers.helpers.TypeUtils
Utility methods focusing on type inspection, particularly with regard to
generics.
Code extracted from Apache Commons Lang 3 - TypeUtils.java and ArrayUtils.java
-
Method Summary
Modifier and TypeMethodDescriptionstatic booleanCheck equality of types.static TypeReturns the raw type if the given type is parameterized, if not returns the type.static booleanisAssignable(Type type, Type toType) Checks if the subject type may be implicitly cast to the target type following the Java generics rules.static Type[]normalizeUpperBounds(Type[] bounds) This method strips out the redundant upper bound types in type variable types and wildcard types (or it would with wildcard types if multiple upper bounds were allowed).
-
Method Details
-
isAssignable
Checks if the subject type may be implicitly cast to the target type following the Java generics rules.
- Parameters:
type- the subject type to be assigned to the target typetoType- the target type- Returns:
trueiftypeis assignable totoType.
-
normalizeUpperBounds
This method strips out the redundant upper bound types in type variable types and wildcard types (or it would with wildcard types if multiple upper bounds were allowed).
Example, with the variable type declaration:
<K extends java.util.Collection<String> & java.util.List<String>>
since
Listis a subinterface ofCollection, this method will return the bounds as if the declaration had been:<K extends java.util.List<String>>
- Parameters:
bounds- an array of types representing the upper bounds of eitherWildcardTypeorTypeVariable, notnull.- Returns:
- an array containing the values from
boundsminus the redundant types.
-
getRawTypeIfParameterized
Returns the raw type if the given type is parameterized, if not returns the type.- Parameters:
type- the type to convert- Returns:
- the raw type if parameterized
-
equals
Check equality of types.- Parameters:
t1- the first typet2- the second type- Returns:
- boolean
-