Package io.sundr.model.functions
Class TypeCast
java.lang.Object
io.sundr.model.functions.TypeCast
This function can be thought as
Types.isInstanceOf(TypeRef, TypeDef, Function) with added bonus that generic
arguments
are resolved.
For example, when TypeCast.to(Map<?,?>) is called on HashMap<String, Integer, the result will be
Optional.of(Map<String, Integer>).
This works also for complex hierarchies with non-trivial type argument substitutions.
Limitation: Arguments involving wildcards are currently not supported.
-
Method Details
-
to
Create the function which casts to the specified target type.- Parameters:
expectedType- The type to which to cast. It must not be an array, and all type arguments (if any) must be unbounded wildcards
-
apply
Perform the type cast, if possible.- Specified by:
applyin interfaceFunction<TypeRef,Optional<ClassRef>> - Parameters:
type- The type which will be cast- Returns:
- If the type can be cast to target type,
Optional.of(targetType<...>)is returned with the type arguments resolved. If the type cannot be cast,Optional.empty()is returned. - Throws:
IllegalStateException- when the type implements or extends target type multiple times with different arguments. Currently, this may also apply to multiple inheritance of wildcard types, even if they were compatible.
-