Annotation Type Covariant
-
@Documented @Retention(RUNTIME) @Target(TYPE) public @interface CovariantA marker annotation, written on a class declaration, that signifies that one or more of the class's type parameters can be treated covariantly. For example, ifMyClasshas a single type parameter that is treated covariantly, and ifBis a subtype ofA, thenSomeClass<B>is a subtype ofSomeClass<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
@Covariantis simply trusted.Here is an example use:
@Covariant(0) public interface Iterator<E extends @Nullable Object> { ... }- See the Checker Framework Manual:
- Covariant type parameters
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description int[]valueThe zero-based indices of the type parameters that should be treated covariantly.
-