Annotation Type KeyFor

public @interface KeyFor

Indicates that the annotated reference of an Object that is a key in a map.

The value of the annotation should be the reference name of the map. The following declaration for example:

   Map<String, String> config = ...;
   @KeyFor("config") String key = "HOSTNAME";

   String hostname = config.get(key);     // known to be non-null
indicates that "HOSTNAME" is a key in config. The Nullness checker deduce this information to deduce that hostname reference is a nonnull reference.

Limitation: The Nullness checker trusts the user and doesn't validate the annotations. Future releases will check for the presence of the key in the map (when possible).

Required Element Summary
Modifier and Type Required Element and Description
 String[] value
          One or more Java expressions.

Element Detail


public abstract String[] value
One or more Java expressions. Each evaluates to a map for which the annotated type is a key.