Top Description Methods
com.google.errorprone.annotations

public @Interface CompatibleWith

extends Annotation
Annotations
@Documented
@Retention:CLASS
@Target:PARAMETER
Imports
java.lang.annotation.Documented, .ElementType, .Retention, .RetentionPolicy, .Target, java.util.Collection

Declares that a parameter to a method must be "compatible with" one of the type parameters in the method's enclosing class, or on the method itself. "Compatible with" means that there can exist a "reference casting conversion" from one type to the other (JLS 5.5.1).

For example, Collection#contains would be annotated as follows:

interface Collection<E> {
  boolean contains(@CompatibleWith("E") Object o);
}

To indicate that invocations of Collection#contains must be passed an argument whose type is compatible with the generic type argument of the Collection instance:

Collection<String> stringCollection = ...;
boolean shouldBeFalse = stringCollection.contains(42); // BUG! int isn't compatible with String

Note

currently, this annotation can't be used if the method overrides another method that has @CompatibleWith already present.

Method Summary

Modifier and TypeMethod and Description
public String
Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString

Method Detail

valueback to summary
public String value()