我测试了代码:
val a : Int = 0x01
val b : Int = 0x03
println(a and b)
得到:
1
但是如果我声明为 Byte
s:
val a : Byte = 0x01
val b : Byte = 0x03
println(a and b)
出现错误:
error: unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@SinceKotlin @InlineOnly public inline infix fun BigInteger.and(other: BigInteger): BigInteger defined in kotlin
println(a and b)
^
我找到了引用:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.experimental/and.html说:
Platform and version requirements: Kotlin 1.1
我检查了我的版本:
C:\>kotlinc.bat -version
info: kotlinc-jvm 1.2.30 (JRE 1.8.0_181-b13)
这是什么意思?
最佳答案
您缺少导入语句:
import kotlin.experimental.and
如果没有导入,编译器会尝试使用 BigIntegers.kt
中的 and
。
关于compiler-errors - 字节和位运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51917306/