I have this enum:
public enum Direction {
LEFT,
RIGHT,
ABOVE,
BELOW
}
Can I get and set a Direction variable that contains 2 or more values, for example:
Direction fromDirection = Direction.LEFT + Direction.ABOVE
If it’s possible, please tell me how to achieve it.
You could use a
java.util.EnumSet:Of course, you could use any other set implementation, but
EnumSettypes are implemented as bit vectors, very space and time efficient and probably the best built-in facility for your goal.You may also want to define a static method in the enum type which checks for valid combinations.