@Documented @Retention(value=RUNTIME) @Target(value=TYPE) public @interface Covariant
MyClass
has a single
type parameter that is treated covariantly, and if B
is a subtype of A
, then
SomeClass<B>
is a subtype of SomeClass<A>
.
Ordinarily, Java treats type parameters invariantly: SomeClass<B>
is unrelated to
(neither a subtype nor a supertype of) SomeClass<A>
.
It is only safe to mark a type parameter as covariant if the type parameter is used in a
read-only way: values of that type are read from but never modified. This property is not
checked; the @Covariant
is simply trusted.
Here is an example use:
@Covariant(0)
public interface Iterator<E extends @Nullable Object> { ... }
Modifier and Type | Required Element and Description |
---|---|
int[] |
value
The zero-based indices of the type parameters that should be treated covariantly.
|