@Documented @Retention(value=CLASS) @Target(value=PARAMETER) public @interface CompatibleWith
For example, Collection.contains(java.lang.Object)
would be annotated as follows:
interface Collection<E> {
boolean contains(@CompatibleWith("E") Object o);
}
To indicate that invocations of Collection.contains(java.lang.Object)
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.
public abstract String value
Copyright © 2021 Google LLC. All rights reserved.