Skip to content

Commit

Permalink
Contra-variant bounds checking in isAssignableTo()
Browse files Browse the repository at this point in the history
  • Loading branch information
knutwannheden committed Nov 6, 2023
1 parent 887e9c6 commit ecb1a44
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ public static boolean isAssignableTo(@Nullable JavaType to, @Nullable JavaType f
JavaType.Primitive toPrimitive = JavaType.Primitive.fromClassName(toFq.getFullyQualifiedName());
if (toPrimitive != null) {
return isAssignableTo(toPrimitive, from);
} else if (toFq.getFullyQualifiedName().equals("java.lang.Object")) {
return true;
}
}
return isAssignableTo(toFq.getFullyQualifiedName(), from);
Expand All @@ -224,6 +226,13 @@ public static boolean isAssignableTo(@Nullable JavaType to, @Nullable JavaType f
}
}
return true;
} else if (toGeneric.getVariance() == JavaType.GenericTypeVariable.Variance.CONTRAVARIANT) {
for (JavaType toBound : toBounds) {
if (!isAssignableTo(from, toBound)) {
return false;
}
}
return true;
}
return false;
} else if (to instanceof JavaType.Variable) {
Expand Down

0 comments on commit ecb1a44

Please sign in to comment.