mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add comment
This commit is contained in:
parent
024dc523bd
commit
c0793d90bb
@ -81,15 +81,20 @@ public class BitStatusUtil {
|
||||
* <li>必须大于0</li>
|
||||
* <li>必须为偶数</li>
|
||||
* </ul>
|
||||
* 原因见:https://github.com/dromara/hutool/pull/3706
|
||||
*
|
||||
* @param args 被检查的状态
|
||||
*/
|
||||
private static void check(final int... args) {
|
||||
for (final int arg : args) {
|
||||
if (arg < 0) {
|
||||
//位运算中 0 在二进制表示中所有位都是 0,它并不能代表任何特定状态
|
||||
//如果 0 被允许作为一个合法状态值,那么在检查状态时(比如通过 has() 方法),它将无法有效区分 0 是代表“无状态”还是代表某个特定状态。
|
||||
//如果允许 0 作为状态,它可能会与清空状态的操作(clear() 方法返回 0)发生混淆,从而导致逻辑上的错误。
|
||||
throw new IllegalArgumentException(arg + " 必须大于等于0");
|
||||
}
|
||||
if ((arg & 1) == 1) {
|
||||
//使用偶数作为状态值,确保每个状态只占用二进制中的一位,从而避免不同状态之间的混淆,确保位运算的准确性。
|
||||
throw new IllegalArgumentException(arg + " 不是偶数");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user