Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java structure holding multiple variables that can be written and read as an integer?

Tags:

java

I am sure this exists, and I believe I did something similar in C quite a while back with bit fields, but I cannot think of how I should do this.

Basically I will have a series of options that can either be on or off. These options describe the operations an application can perform on a file e.g.

STRUCTURE
{
  EXECUTE
  READ
  WRITE
}

If this structure were a bit field I would like to be able to set structure to a value that represents both READ and WRITE but not execute (e.g. 3). If I were to read this structure it could give me 3 thus I would know that given this value execute should be denied. A bit field solution may not necessarily be the best solution in this case though.

like image 741
Críostóir Ó Catháin Avatar asked Feb 03 '26 03:02

Críostóir Ó Catháin


1 Answers

Definitely an EnumSet, as 'zapl' recommended.

Or have a List of Enum, but the latter makes more sense.

like image 65
abdelrahman-sinno Avatar answered Feb 05 '26 20:02

abdelrahman-sinno