compiler-errors - 字节和位运算符

标签 compiler-errors kotlin byte bitwise-operators

我测试了代码:

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

得到:

1

但是如果我声明为 Bytes:

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/

相关文章:

java - 为什么不打印此代码?有什么错误?

java - Netty 连接同时到达的消息

java - Java接口(interface)的问题

android - 我如何从我的Android应用程序共享whatsapp语音笔记(.opus)文件?

list - 使用自定义相等函数在 Kotlin 中减去两个列表

Kotlin - 如何使用 OkHttp Kotlin 设置连接超时

java整数转字节,字节转整数

string - 如何在 Golang 中解决(字符串和字节类型不匹配)

Haskell 代码行未编译 : "Illegal datatype context"

c++ - 精神文法无法编译 : function template argument error?