/** * <p> * Checks if the subject type may be implicitly cast to the target type following the Java generics rules. * </p> * * @param type the subject type to be assigned to the target type * @param toType the target type * @return <code>true</code> if <code>type</code> is assignable to <code>toType</code>. */ public static boolean isAssignable(Type type, Type toType) { return isAssignable(type, toType, null); }
/** * <p> * Checks if the subject type may be implicitly cast to the target type following the Java generics rules. * </p> * * @param type the subject type to be assigned to the target type * @param toType the target type * @param typeVarAssigns optional map of type variable assignments * @return <code>true</code> if <code>type</code> is assignable to <code>toType</code>. */ private static boolean isAssignable(Type type, Type toType, Map<TypeVariable<?>, Type> typeVarAssigns) { if (toType == null || toType instanceof Class<?>) { return isAssignable(type, (Class<?>) toType); } if (toType instanceof ParameterizedType) { return isAssignable(type, (ParameterizedType) toType, typeVarAssigns); } if (toType instanceof GenericArrayType) { return isAssignable(type, (GenericArrayType) toType, typeVarAssigns); } if (toType instanceof WildcardType) { return isAssignable(type, (WildcardType) toType, typeVarAssigns); } // * if (toType instanceof TypeVariable<?>) { return isAssignable(type, (TypeVariable<?>) toType, typeVarAssigns); } // */ throw new IllegalStateException("found an unhandled type: " + toType); }
if (type1 != type2 && isAssignable(type2, type1, null)) { subtypeFound = true; break;
if (isAssignable(midClass, superClass) && isAssignable(genericInterface, (Type) midClass)) { genericInterface = midType;
return cls.isArray() && isAssignable(cls.getComponentType(), toComponentType, typeVarAssigns); return isAssignable(((GenericArrayType) type).getGenericComponentType(), toComponentType, typeVarAssigns); if (isAssignable(bound, toGenericArrayType)) { return true; if (isAssignable(bound, toGenericArrayType)) { return true;
return isAssignable(getRawType((ParameterizedType) type), toClass); if (isAssignable(bound, toClass)) { return true; && isAssignable(((GenericArrayType) type).getGenericComponentType(), toClass.getComponentType());
if (isAssignable(bound, toTypeVariable, typeVarAssigns)) { return true;
if (!isAssignable(cls, toClass)) { return null;
&& !(toTypeArg instanceof WildcardType && isAssignable(fromTypeArg, toTypeArg, typeVarAssigns))) { return false;
if (!isAssignable(cls, toClass)) { return null;
.filter(cls -> Types.isAssignable(cls,elementType) && cls != elementType) .toArray(length -> new Class<?>[length]); value.ok(values); .filter(cls -> Types.isAssignable(cls,classType) && cls != classType) .collect(Collectors.toList()); value.ok(values);
for (Type bound : getImplicitUpperBounds((WildcardType) type)) { if (isAssignable(bound, toClass)) { return getTypeArguments(bound, toClass, subtypeVarAssigns); for (Type bound : getImplicitBounds((TypeVariable<?>) type)) { if (isAssignable(bound, toClass)) { return getTypeArguments(bound, toClass, subtypeVarAssigns);
if (!isAssignable(bound, toBound, typeVarAssigns)) { return false; if (!isAssignable(toBound, bound, typeVarAssigns)) { return false; if (!isAssignable(type, substituteTypeVariables(toBound, typeVarAssigns), typeVarAssigns)) { return false; if (!isAssignable(substituteTypeVariables(toBound, typeVarAssigns), type, typeVarAssigns)) { return false;
if (!isAssignable(cls, superClass)) { return null;