@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 clients use the type parameter in a read-only way: clients read values of that type but never modify them.
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.
|