Typedef Annotations: @IntDef, @StringDef
The annotations package includes a number of useful metadata annotations you can decorate your own code with, to help catch bugs.
Just add the dependency in the
Combining constants with flags
IntDef#flag() attribute set to
true, multiple constants can be combined.
Using the same example in this topic:
Users can combine the allowed constants with a flag (such as
This annotation ensures that only the valid integer constants that you expect are used.
The following example illustrates the steps to create an annotation:
They also enable code completion to automatically offer the allowed constants.
When you build this code, a warning is generated if the type parameter does not reference one of the defined constants.
This modified text is an extract of the original Stack Overflow Documentation created by following contributors
and released under CC BY-SA 3.0