Multiple flags in one int value

I have an int variable that contains several flags, for example:

int styles = ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED; 

I can check for a flag

 boolean expanded = (styles & ExpandableComposite.EXPANDED) != 0; 

How can I remove the flag value from styles , i.e. dynamically remove ExpandableComposite.EXPANDED without knowing the exact flags that are set in styles ?

+6
java eclipse
source share
1 answer

this is an old C idiom still working in Java:

 styles &= ~ExpandableComposite.EXPANDED; 

However, these days (> = Java 1.5) you should consider using:

+10
source share

All Articles