- Kotlin Standard Library Cookbook
- Samuel Urbanowicz
- 103字
- 2021-07-23 19:05:56
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")
推薦閱讀
- C語言程序設計教程
- Node.js+Webpack開發(fā)實戰(zhàn)
- Deploying Node.js
- 復雜軟件設計之道:領域驅動設計全面解析與實戰(zhàn)
- iOS 9 Game Development Essentials
- Django開發(fā)從入門到實踐
- C和C++安全編碼(原書第2版)
- Python高效開發(fā)實戰(zhàn):Django、Tornado、Flask、Twisted(第3版)
- Unity UI Cookbook
- 一本書講透Java線程:原理與實踐
- Extending Unity with Editor Scripting
- INSTANT Apache ServiceMix How-to
- Visual Basic程序設計實驗指導及考試指南
- 百萬在線:大型游戲服務端開發(fā)
- 你真的會寫代碼嗎