Annotation Type KeyFor
-
@Documented @Retention(RUNTIME) @Target({TYPE_USE,TYPE_PARAMETER}) @SubtypeOf(UnknownKeyFor.class) public @interface KeyFor
Indicates that the value assigned to the annotated variable is a key for at least the given map(s).The value of the annotation is the reference name of the map. Suppose that
config
is aMap<String, String>
. Then the declaration
indicates that "HOSTNAME" is a key in@KeyFor("config") String key = "HOSTNAME";
config
.The value of the annotation can also be a set of reference names of the maps. If
defaultConfig
is also aMap<String, String>
, then
indicates that "HOSTNAME" is a key in@KeyFor({"config","defaultConfig"}) String key = "HOSTNAME";
config
and indefaultConfig
.You do not usually need to write
@KeyFor
on the key type in a map. That is, you can declare variableMap<String, Integer> myMap;
and the Nullness Checker will apply@KeyFor
as appropriate. If you redundantly write@KeyFor
, as inMap<@KeyFor("myMap") String, Integer> myMap;
, then your code is more verbose, and more seriously the Nullness Checker will issue errors when calling methods such asMap.put
.- See Also:
EnsuresKeyFor
,EnsuresKeyForIf
- See the Checker Framework Manual:
- Map Key Checker
-
-
Required Element Summary
Required Elements Modifier and Type Required Element Description java.lang.String[]
value
Java expression(s) that evaluate to a map for which the annotated type is a key.
-
-
-
Element Detail
-
value
@JavaExpression java.lang.String[] value
Java expression(s) that evaluate to a map for which the annotated type is a key.- See the Checker Framework Manual:
- Syntax of Java expressions
-
-