in bval-jsr/src/main/java/org/apache/bval/util/reflection/TypeUtils.java [510:564]
private static boolean isAssignable(final Type type, final GenericArrayType toGenericArrayType,
final Map<TypeVariable<?>, Type> typeVarAssigns) {
if (type == null) {
return true;
}
// only a null type can be assigned to null type which
// would have cause the previous to return true
if (toGenericArrayType == null) {
return false;
}
// all types are assignable to themselves
if (toGenericArrayType.equals(type)) {
return true;
}
final Type toComponentType = toGenericArrayType.getGenericComponentType();
if (type instanceof Class<?>) {
final Class<?> cls = (Class<?>) type;
// compare the component types
return cls.isArray()
&& isAssignable(cls.getComponentType(), toComponentType, typeVarAssigns);
}
if (type instanceof GenericArrayType) {
// compare the component types
return isAssignable(((GenericArrayType) type).getGenericComponentType(),
toComponentType, typeVarAssigns);
}
if (type instanceof WildcardType) {
// so long as one of the upper bounds is assignable, it's good
return Stream.of(getImplicitUpperBounds((WildcardType) type))
.anyMatch(bound -> isAssignable(bound, toGenericArrayType));
}
if (type instanceof TypeVariable<?>) {
// probably should remove the following logic and just return false.
// type variables cannot specify arrays as bounds.
return Stream.of(getImplicitBounds((TypeVariable<?>) type))
.anyMatch(bound -> isAssignable(bound, toGenericArrayType));
}
if (type instanceof ParameterizedType) {
// the raw type of a parameterized type is never an array or
// generic array, otherwise the declaration would look like this:
// Collection[]< ? extends String > collection;
return false;
}
throw new IllegalStateException("found an unhandled type: " + type);
}