Kotlin:是否可以重复使用 componentN 运算符?
Kotlin: Is it possible to use componentN operator in repeat?
我正在通过 hyperskill 学习 kotlin。
我很好奇是否可以将 componentN 运算符分配给 repeat 函数,如下所示:
val (a, b, c) = repeat(3) { BigInteger(readLine()!!) }
我尝试使用 componentN
运算符扩展我的一些功能,但我不知道如何使用 repeat
repeat
没有 return 任何东西,这意味着您不能将此功能用于 destructuring declarations。
但是您可以将 Range
与 map
、List
或 Array
一起使用:
val (a, b, c) = (1..3).map { BigInteger(readLine()!!) }
//or
val (a, b, c) = Array(3) { BigInteger(readLine()!!) }
我正在通过 hyperskill 学习 kotlin。
我很好奇是否可以将 componentN 运算符分配给 repeat 函数,如下所示:
val (a, b, c) = repeat(3) { BigInteger(readLine()!!) }
我尝试使用 componentN
运算符扩展我的一些功能,但我不知道如何使用 repeat
repeat
没有 return 任何东西,这意味着您不能将此功能用于 destructuring declarations。
但是您可以将 Range
与 map
、List
或 Array
一起使用:
val (a, b, c) = (1..3).map { BigInteger(readLine()!!) }
//or
val (a, b, c) = Array(3) { BigInteger(readLine()!!) }