我希望您能将此答案的代码转换为Kotlin:https://dev59.com/AHA65IYBdhLWcg3w-z5A#5402769
我将其粘贴到Intellij中:
当我在Intellij中选择将代码转换为Kotlin时,会得到以下输出:
在任何时候,我都会遇到这个错误:
private int decodeInt() {
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
}
当我在Intellij中选择将代码转换为Kotlin时,会得到以下输出:
private fun decodeInt(): Int {
return (bytes[pos++] and 0xFF shl 24 or (bytes[pos++] and 0xFF shl 16)
or (bytes[pos++] and 0xFF shl 8) or (bytes[pos++] and 0xFF))
}
在任何时候,我都会遇到这个错误:
0xFF
。The integer literal does not conform to the expected type Byte
在它后面添加 .toByte()
之后,我能够解决这个错误。
在所有的左移操作(shl
)中,我都会遇到这个错误:
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
@SinceKotlin @InlineOnly public infix inline fun BigInteger.shl(n: Int): BigInteger defined in kotlin
我无法解决这个问题... 我对Java/Kotlin中的位移操作并不了解...
这个问题的Kotlin代码应该是什么呢?