public final class Wildcard extends Object implements TypeArg
A wildcard is a type argument, see TypeArg
.
See static convenience methods for creating `Wildcard` objects.
Note: a wildcard is *not* a type.
See also article Capturing Wildcards
Constructor and Description |
---|
Wildcard(ReferenceType<?> upperBound,
ReferenceType<?> lowerBound)
Create a wildcard with bounds.
|
Instance Methods | |
---|---|
ReferenceType<?> |
getUpperBound()
Get the upper bound.
|
ReferenceType<?> |
getLowerBound()
Get the lower bound.
|
int |
hashCode() |
boolean |
equals(Object obj)
Whether this wildcard is equal to another wildcard.
|
String |
toString(boolean full)
A textual description of the wildcard.
|
String |
toString()
A textual description of the wildcard.
|
Static Methods | |
Wildcard |
extends_(Class<?> upperBound)
Create a wildcard with an upper bound.
|
Wildcard |
extends_(ReferenceType<?> upperBound)
Create a wildcard with an upper bound.
|
Wildcard |
super_(Class<?> lowerBound)
Create a wildcard with a lower bound.
|
Wildcard |
super_(ReferenceType<?> lowerBound)
Create a wildcard with a lower bound.
|
Wildcard |
unbounded()
Create an unbounded wildcard.
|
public Wildcard(ReferenceType<?> upperBound, ReferenceType<?> lowerBound)
`upperBound` must be non-null; it can be the Object type
.
`lowerBound` must be non-null; it can be the null type
.
( Strictly according to JLS, syntactically, a wildcard is either upper bounded or lower bounded, but not both. That is, semantically, either the lower bound is null-type, or the upper bound is `Object`, or both. We do not enforce or require that property in our library. )
public static Wildcard extends_(Class<?> upperBound)
This method is equivalent to
extends_(ClassType.of(upperBound))
Example
TypeArg V = Wildcard.extends_(Number.class); // ? extends Number
public static Wildcard extends_(ReferenceType<?> upperBound)
The lower bound is the null type.
public static Wildcard super_(Class<?> lowerBound)
This method is equivalent to
super_(ClassType.of(lowerBound))
Example
TypeArg V = Wildcard.super_(Number.class); // ? super Number
public static Wildcard super_(ReferenceType<?> lowerBound)
The upper bound is the Object
type.
public static Wildcard unbounded()
The upper bound is `Object`, and the lower bound is the null type.
Example
ClassType.of(List.class, Wildcard.unbounded()); // List<?>
public ReferenceType<?> getUpperBound()
public ReferenceType<?> getLowerBound()
public boolean equals(Object obj)
Two wildcards are equal if their bounds are equal.
public String toString(boolean full)
If `full==false`, simpler names are used for bound types.
public String toString()
This method is equivalent to toString(true)
.