我正在定义一个简单的函数来执行一些按位运算:
def getBit(num:Int, i:Int):Boolean = (num & (1 << i) != 0)
但我收到此错误:
<console>:7: error: overloaded method value & with alternatives:
(x: Long)Long <and>
(x: Int)Int <and>
(x: Char)Int <and>
(x: Short)Int <and>
(x: Byte)Int
cannot be applied to (Boolean)
def getBit(num:Int, i:Int):Boolean = (num & (1 << i) != 0)
为什么我不能使用&
运算符?我该如何解决这个错误?