Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Byte and bitwise operators

I tested the code:

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

and got:

1

But if I declare as Bytes:

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

got error:

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)
          ^

I found the reference: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.experimental/and.html saying:

Platform and version requirements: Kotlin 1.1

I checked my version:

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

What does it mean?

like image 964
BingLi224 Avatar asked Apr 11 '26 12:04

BingLi224


1 Answers

You are missing the import statement:

import kotlin.experimental.and

Without the import the compiler tries to use the and found in BigIntegers.kt.

like image 60
DVarga Avatar answered Apr 15 '26 00:04

DVarga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!