Skip to content

Commit 3a83547

Browse files
committed
Types: improve the wildcard methods
Nowhere in the code do we use the wildcard(upperBound, lowerBound) method to set a lower bound. But we often want to set a single upper bound, or multiple upper bounds, without any lower bounds. As such, this commit transforms wildcard() into wildcard(Type...), for improved convenience of usage.
1 parent 6deafe6 commit 3a83547

File tree

3 files changed

+6
-20
lines changed

3 files changed

+6
-20
lines changed

scijava-common3/src/main/java/org/scijava/common3/Types.java

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -632,26 +632,12 @@ public static ParameterizedType parameterize(final Class<?> rawType,
632632
}
633633

634634
/**
635-
* Creates a new {@link WildcardType} with no upper or lower bounds (i.e.,
636-
* {@code ?}).
635+
* Creates a new {@link WildcardType} with the given upper bound(s).
637636
*
638637
* @return The newly created {@link WildcardType}.
639638
*/
640-
public static WildcardType wildcard() {
641-
return wildcard(null, (Type) null);
642-
}
643-
644-
/**
645-
* Creates a new {@link WildcardType} with the given upper and/or lower bound.
646-
*
647-
* @param upperBound Upper bound of the wildcard, or null for none.
648-
* @param lowerBound Lower bound of the wildcard, or null for none.
649-
* @return The newly created {@link WildcardType}.
650-
*/
651-
public static WildcardType wildcard(final Type upperBound,
652-
final Type lowerBound)
653-
{
654-
return new TypeUtils.WildcardTypeImpl(upperBound, lowerBound);
639+
public static WildcardType wildcard(Type... upperBounds) {
640+
return wildcard(upperBounds, null);
655641
}
656642

657643
/**

scijava-common3/src/test/java/org/scijava/common3/GreatestCommonSupertypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ class C<T extends Base> {}
195195

196196
@Test
197197
public void testWildcardType() {
198-
Type qNThing = Types.wildcard(NThing.class, null);
198+
Type qNThing = Types.wildcard(NThing.class);
199199
Type typeWithWildcard = Types.parameterize(List.class, new Type[] { qNThing });
200200
Type t1 = ((ParameterizedType) typeWithWildcard).getActualTypeArguments()[0];
201201
Type t2 = XThing.class;

scijava-common3/src/test/java/org/scijava/common3/TypesTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ class C<T extends Number> {}
216216
var listT = Types.parameterize(List.class, new Type[] { t });
217217
var listNumber = Types.parameterize(List.class, new Type[] { Number.class });
218218
var listInteger = Types.parameterize(List.class, new Type[] { Integer.class });
219-
var listExtendsNumber = Types.parameterize(List.class, new Type[] { Types.wildcard(Number.class, null) });
219+
var listExtendsNumber = Types.parameterize(List.class, new Type[] { Types.wildcard(Number.class) });
220220
var listListRaw = Types.parameterize(List.class, new Type[] { List.class });
221221
var listListInteger = Types.parameterize(List.class, new Type[] { listInteger });
222222

@@ -268,7 +268,7 @@ class C<N extends Number, S extends String, T extends List<N>> {}
268268
final Type listS = Types.parameterize(List.class, new Type[] { s });
269269
final Type listNumber = Types.parameterize(List.class, new Type[] { Number.class });
270270
final Type listInteger = Types.parameterize(List.class, new Type[] { Integer.class });
271-
final Type listExtendsNumber = Types.parameterize(List.class, new Type[] { Types.wildcard(Number.class, null) });
271+
final Type listExtendsNumber = Types.parameterize(List.class, new Type[] { Types.wildcard(Number.class) });
272272
// T list = (T) new ArrayList<N>();
273273
assertTrue(Types.isAssignable(listN, t));
274274
// T list = (T) new ArrayList<Number>();

0 commit comments

Comments
 (0)