The value of the annotation is the reference name of the map. Suppose that config is a
Map<String, String>. Then the declaration
@KeyFor("config") String key = "HOSTNAME";
indicates that "HOSTNAME" is a key in config.
The value of the annotation can also be a set of reference names of the maps. If defaultConfig is also a Map<String, String>, then
@KeyFor({"config","defaultConfig"}) String key = "HOSTNAME";
indicates that "HOSTNAME" is a key in config and in defaultConfig.
You do not usually need to write @KeyFor on the key type in a map. That is, you can
declare variable Map<String, Integer> myMap; and the Nullness Checker will apply
@KeyFor as appropriate. If you redundantly write @KeyFor, as in Map<@KeyFor("myMap") String, Integer> myMap;, then your code is more verbose, and more seriously
the Nullness Checker will issue errors when calling methods such as Map.put.
EnsuresKeyFor, EnsuresKeyForIf
| Modifier and Type | Method and Description |
|---|---|
| public String[] |
| value | back to summary |
|---|---|
| public String[] value() Java expression(s) that evaluate to a map for which the annotated type is a key.
| |