Using the true value of the IntDef # flag () attribute allows you to combine multiple constants.
Users can combine allowed constants with a flag (for example, |, & amp ;, ^).
For example:
public static final int DISPLAY_OP_1 = 1; public static final int DISPLAY_OP_2 = 1<<1; public static final int DISPLAY_OP_3 = 1<<2; @IntDef ( flag=true, value={ DISPLAY_OP_1, DISPLAY_OP_2, DISPLAY_OP_3 } ) @Retention(RetentionPolicy.SOURCE) public @interface DisplayOptions{} public void setIntDefFlag(@DisplayOptions int ops) { ... }
and use setIntDefFalg() with '|'
setIntDefFlag(DisplayOptions.DISPLAY_OP1|DisplayOptions.DISPLAY_OP2);
fuxi chu
source share