System.out.println(5 & (~1)); 比如,通过二进制位运算实现权限设置 newAuth.getAuthority() 为表示权限的数字,attEnum.getIndex() 指的是某一个权限的位数,代码如下 if (flag) { Long tmp = newAuth.getAuthority() | attEnum.getIndex();
newAuth.setAuthority(tmp); } else { Long tmp = newAuth.getAuthority() & (~attEnum.getIndex()); newAuth.setAuthority(tmp); }
public enum AuthorityAttributeEnum { NAME(1), MOBILE(2), EMAIL(4); private int index; // 构造方法 AuthorityAttributeEnum(int index) { this.index = index; } public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } }
原创文章,欢迎转载,转载请注明出处! 标签:getIndex,index,java,运算,int,取反,attEnum,newAuth,tmp From: https://www.cnblogs.com/acm-bingzi/p/java_reverse.html