kotlin - Kotlin:是否可以重复使用 componentN 运算符?
问题描述
我正在从 hyperskill 学习 kotlin。
我很好奇是否可以将 componentN 运算符分配给重复功能,如下所示:
val (a, b, c) = repeat(3) { BigInteger(readLine()!!) }
我尝试使用componentN
操作员扩展我的一些功能,但我不知道如何使用repeat
解决方案
repeat
不返回任何内容,这意味着您不能使用此函数来解构声明。但是您可以使用Range
withmap
或:List
Array
val (a, b, c) = (1..3).map { BigInteger(readLine()!!) }
//or
val (a, b, c) = Array(3) { BigInteger(readLine()!!) }
推荐阅读
- java - FileNotFoundException 使用 Eclipse 编辑器
- tensorflow - 从机器学习中解读混淆矩阵的值
- xaml - Xamarin.Forms:当使用网格值设置大小时,微小的图标会变得如此轻微
- c# - 如何在单个解决方案文件中的两个 WebApp 中引用和使用相同的类库?
- linux - 使用 Openflow 的 ODL 镁合金
- spring - Spring Boot 微服务正在使用 Kubernetes 集群中的 pod 名称作为主机名注册到 Eureka - docker desktop
- mysql - 在非空列的空值重复键更新上插入 ...
- r - R ggplot2 - 底部的图例被剪切,如何动态找到图例的最佳列数?
- java - Assertj 3.16.1 中是否不推荐使用“hasOnlyElementsOfType”方法
- python - 垂直打印数组