Kotlin 如何使用ByteArray.getOrElse
我不理解如何为`ByteArray.getOrElse()函数指定默认值 我试过:Kotlin 如何使用ByteArray.getOrElse,kotlin,Kotlin,我不理解如何为`ByteArray.getOrElse()函数指定默认值 我试过: myInt = dat.getOrElse(0, 0).toInt() 但编译器抱怨出现以下错误: The integer literal does not conform to the expected type (Int) -> Byte 如何指定默认值?第二个参数是函数文本 myInt = dat.getOrElse(100, { /** what is there is no element 1
myInt = dat.getOrElse(0, 0).toInt()
但编译器抱怨出现以下错误:
The integer literal does not conform to the expected type (Int) -> Byte
如何指定默认值?第二个参数是函数文本
myInt = dat.getOrElse(100, { /** what is there is no element 100*/ 0 })
第二个参数是一个函数文本
myInt = dat.getOrElse(100, { /** what is there is no element 100*/ 0 })
第二个参数(
defaultValue
)的预期类型是(Int)->Byte
,它是一个lambda,接受Int
并返回Byte
myInt = dat.getOrElse(index = 100, defaultValue = {
i ->
// use i to calcuate your Byte that should be returned...
// or return a fixed value
i * 1 // for example
})
签字人:
第二个参数(
defaultValue
)的预期类型是(Int)->Byte
,它是一个lambda,接受Int
并返回Byte
myInt = dat.getOrElse(index = 100, defaultValue = {
i ->
// use i to calcuate your Byte that should be returned...
// or return a fixed value
i * 1 // for example
})
签字人: