Class TypeUtils
- java.lang.Object
-
- io.smallrye.reactive.messaging.providers.helpers.TypeUtils
-
public class TypeUtils extends Object
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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequals(Type t1, Type t2)Check equality of types.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 Detail
-
isAssignable
public static boolean isAssignable(Type type, Type toType)
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
public 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).
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.
-
-