Class TypeUtils
- java.lang.Object
-
- io.smallrye.reactive.messaging.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 int[]
add(int[] array, int element)
static boolean
equals(Type t1, Type t2)
Check equality of types.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.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).static String
toString(Type type)
-
-
-
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:
true
iftype
is 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
List
is 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 eitherWildcardType
orTypeVariable
, notnull
.- Returns:
- an array containing the values from
bounds
minus the redundant types.
-
equals
public static boolean equals(Type t1, Type t2)
Check equality of types.- Parameters:
t1
- the first typet2
- the second type- Returns:
- boolean
-
add
public static int[] add(int[] array, int element)
-
-