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.
| Modifier and Type | Method and Description |
|---|---|
| public String |
| value | back to summary |
|---|---|
| public String value() | |