官术网_书友最值得收藏!

There's more...

The Kotlin standard library provides ready to use Pair and Triple classes. We can use them to return two and three values of any type. This eliminates the need to create a dedicated data classes for the return type. On the other hand, using data classes gives us the ability to operate on more meaningful names, which adds more clarity to the code.

The following example demonstrates using the Pair class to return two objects at the same time:

fun getBestScore(): Pair<String, Int> = Pair("Max", 1000)
val (name, score) = getBestScore()
print("User $name has the best score of $score points")
主站蜘蛛池模板: 北碚区| 奉化市| 苗栗县| 郁南县| 莫力| 区。| 手游| 静海县| 开原市| 阿拉善右旗| 云南省| 和政县| 石屏县| 隆安县| 包头市| 广汉市| 通城县| 安平县| 梁河县| 宁都县| 彰化市| 舟山市| 伊宁县| 岐山县| 深水埗区| 聂荣县| 铜鼓县| 扎赉特旗| 遵义县| 长治县| 临澧县| 樟树市| 河源市| 西贡区| 株洲县| 南溪县| 沧源| 高淳县| 安庆市| 无棣县| 南华县|