Skip to content

Commit 92cf7f1

Browse files
izeyesnicoll
authored andcommitted
Introduce internal constants for implicit bounds in TypeUtils
See gh-30423
1 parent 8a8fb31 commit 92cf7f1

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

spring-core/src/main/java/org/springframework/util/TypeUtils.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
*/
3737
public abstract class TypeUtils {
3838

39+
private static final Type[] IMPLICIT_LOWER_BOUNDS = { null };
40+
private static final Type[] IMPLICIT_UPPER_BOUNDS = { Object.class };
41+
3942
/**
4043
* Check if the right-hand side type may be assigned to the left-hand side
4144
* type following the Java generics rules.
@@ -196,20 +199,14 @@ private static Type[] getLowerBounds(WildcardType wildcardType) {
196199
Type[] lowerBounds = wildcardType.getLowerBounds();
197200

198201
// supply the implicit lower bound if none are specified
199-
if (lowerBounds.length == 0) {
200-
lowerBounds = new Type[] { null };
201-
}
202-
return lowerBounds;
202+
return (lowerBounds.length == 0 ? IMPLICIT_LOWER_BOUNDS : lowerBounds);
203203
}
204204

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

208208
// supply the implicit upper bound if none are specified
209-
if (upperBounds.length == 0) {
210-
upperBounds = new Type[] { Object.class };
211-
}
212-
return upperBounds;
209+
return (upperBounds.length == 0 ? IMPLICIT_UPPER_BOUNDS : upperBounds);
213210
}
214211

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

0 commit comments

Comments
 (0)