我正在尝试复制数组:

System.arraycopy(ret, 2, crcArray, 0, crcArray.size)

ret和crcArray均为kotlin UByteArray类型。

代码崩溃了
java.lang.ArrayStoreException: source of type kotlin.UByteArray is not an array

有没有一种方法可以使用系统方法复制ubytearrays,还是我必须手动进行?

最佳答案

您可以为此使用UByteArray.copyInto(...):

val a = ubyteArrayOf(1u, 2u)
val b = UByteArray(2)

a.copyInto(b)
println(b)
UByteArray(storage=[1, 2])

关于arrays - Kotlin UByteArray和System.arraycopy,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57854184/

10-09 09:21