Z
z-man
I tried hard to find on google some reference about bitwise (flags)
native enums in Java 1.5, without success.
What's the proper way to define and compare bitwise enums (see below)?
Thank you!
public enum MyFlags
{
FlagA(1),
FlagB(2);
private final int bit;
MyFlags(int bit)
{
this.bit = bit;
}
public int getBit()
{
return bit;
}
}
....
MyFlags flags = FlagA + FlagB;
// Question: Is this bitwise comparison legal?
if((flags & FlagB) == FlagB)
System.out.println("Caught!");
else
System.out.println("Missed (should not happen).");
native enums in Java 1.5, without success.
What's the proper way to define and compare bitwise enums (see below)?
Thank you!
public enum MyFlags
{
FlagA(1),
FlagB(2);
private final int bit;
MyFlags(int bit)
{
this.bit = bit;
}
public int getBit()
{
return bit;
}
}
....
MyFlags flags = FlagA + FlagB;
// Question: Is this bitwise comparison legal?
if((flags & FlagB) == FlagB)
System.out.println("Caught!");
else
System.out.println("Missed (should not happen).");