enum « bit « Java Data Type Q&A





1. Can I use bitwise OR for Java Enums    stackoverflow.com

Suppose you have an enum Direction

enum Direction{
    North,South,East West
}
Could I write a method that uses bitwise or's to compare multiple enums
public boolean canGoDirection(Direction dir){
     ...

2. Is there a way to bitwise-OR enums in Java?    stackoverflow.com

I'm using a state machine, and the code's getting really verbose when testing against a large number of possible states.

enum Mood {
    HAPPY, SAD, CALM, SLEEPY, OPTIMISTIC, ...

3. How can I combine 2 bits in a single field using an EnumSet?    stackoverflow.com

Given a binary string coded on 1 byte, is it possible to map several of that byte's bits into an enum value ?
e.g. : suppose I want to cut my field ...

4. FoHow do Enum where can have something be two of its values - like bitwise?    forums.oracle.com

I have some font objects and I want to make an enum for the styles: NORMAL, ITALIC, BOLD, BOLD+ITALIC. The last one is confusing me. If I make it an enum, how can i allow the variable to be two values (so allow adding them like bitwise)? And how do I make it so that FontStyles.values() can include the last one? ...