小编Bin*_*224的帖子

字节和按位运算符

我测试了代码:

val a : Int = 0x01
val b : Int = 0x03
println(a and b)
Run Code Online (Sandbox Code Playgroud)

得到了:

1
Run Code Online (Sandbox Code Playgroud)

但如果我宣布为Bytes:

val a : Byte = 0x01
val b : Byte = 0x03
println(a and b)
Run Code Online (Sandbox Code Playgroud)

得到错误:

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)
          ^
Run Code Online (Sandbox Code Playgroud)

我找到了参考:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.experimental/and.html说:

平台和版本要求:Kotlin 1.1

我检查了我的版本:

C:\>kotlinc.bat -version
info: kotlinc-jvm …
Run Code Online (Sandbox Code Playgroud)

byte compiler-errors bitwise-operators kotlin

2
推荐指数
1
解决办法
128
查看次数

标签 统计

bitwise-operators ×1

byte ×1

compiler-errors ×1

kotlin ×1