字节与位运算符

3

我测试了这段代码:

val a : Int = 0x01
val b : Int = 0x03
println(a and b)

并获得:

1

但如果我声明为 Byte 类型:

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,上面写着:

平台和版本要求:Kotlin 1.1

我查看了自己的版本:

C:\>kotlinc.bat -version
info: kotlinc-jvm 1.2.30 (JRE 1.8.0_181-b13)

这是什么意思?

1个回答

6
您缺少导入语句:
import kotlin.experimental.and

如果没有导入,编译器会尝试使用 BigIntegers.kt 中找到的 and


为什么Intellj IDEA不建议这样做呢?:) - Vlad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接