Annotation Interface Covariant


@Documented @Retention(RUNTIME) @Target(TYPE) public @interface Covariant
A 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, if 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> { ... }
 
See the Checker Framework Manual:
Covariant type parameters
  • Required Element Summary

    Required Elements
    Modifier and Type
    Required Element
    Description
    int[]
    The zero-based indices of the type parameters that should be treated covariantly.
  • Element Details

    • value

      int[] value
      The zero-based indices of the type parameters that should be treated covariantly.