I have an enumeration that I am trying to initialize from a long value that comes from the database.
public enum ArticlePermission {
NONE(0),
CAN_READ(2),
CAN_EDIT(4),
CAN_DELETE(8),
CAN_CREATE(16);
private long _value;
public ArticlePermission(int val) {
this._value = val;
}
public long getValue() {
return this._value;
}
public EnumSet<ArticlePermission> init(long val) {
EnumSet<ArticlePermission> es = EnumSet.of(ArticlePermission.NONE);
for(ArticlePermission p : values()) {
if(val & p.getValue() != 0) {
es.add(p);
}
}
return es;
}
}
I’m getting a compile error saying the & operator cannot be used on a long value.
How can I do this correctly then?
Or if you really did want to do a bitwise comparison, you just need extra parentheses: