Skip to content

Commit

Permalink
Merge pull request #30423 from izeye
Browse files Browse the repository at this point in the history
* pr/30423:
  Polish "Introduce internal constants for implicit bounds in TypeUtils"
  Introduce internal constants for implicit bounds in TypeUtils

Closes gh-30423
  • Loading branch information
snicoll committed May 5, 2023
2 parents 8a8fb31 + 88361a4 commit da37dee
Showing 1 changed file with 6 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
*/
public abstract class TypeUtils {

private static final Type[] IMPLICIT_LOWER_BOUNDS = { null };

private static final Type[] IMPLICIT_UPPER_BOUNDS = { Object.class };

/**
* Check if the right-hand side type may be assigned to the left-hand side
* type following the Java generics rules.
Expand Down Expand Up @@ -196,20 +200,14 @@ private static Type[] getLowerBounds(WildcardType wildcardType) {
Type[] lowerBounds = wildcardType.getLowerBounds();

// supply the implicit lower bound if none are specified
if (lowerBounds.length == 0) {
lowerBounds = new Type[] { null };
}
return lowerBounds;
return (lowerBounds.length == 0 ? IMPLICIT_LOWER_BOUNDS : lowerBounds);
}

private static Type[] getUpperBounds(WildcardType wildcardType) {
Type[] upperBounds = wildcardType.getUpperBounds();

// supply the implicit upper bound if none are specified
if (upperBounds.length == 0) {
upperBounds = new Type[] { Object.class };
}
return upperBounds;
return (upperBounds.length == 0 ? IMPLICIT_UPPER_BOUNDS : upperBounds);
}

public static boolean isAssignableBound(@Nullable Type lhsType, @Nullable Type rhsType) {
Expand Down

0 comments on commit da37dee

Please sign in to comment.