我有枚举;
enum testMe {
one,
two,
three;
long longValue() {
return 1<<ordinal();
}
}
for (testMe myLoop = testMe.values()) {
System.out.println(value.longValue() + ":" + myLoop);
}
遍历枚举给了我对枚举中值的序数变化的期望。但是,我需要对我传入的参数进行限定;
Long myLong = 3;
for (testMe myLoop = testMe.values()) {
if ((myLong & value.longValue()) != 0) {
System.out.println(value.longValue() + ":" + myLoop);
}
}
在这种情况下,只会打印一和二。但是,此方法仅适用于枚举中的 32 个值。有人知道如何使用 BigInteger 吗???
BigInteger longValue() {
BigInteger one = BigInteger.valueOf(1);
return one.shiftLeft(ordinal());
谢谢 C