- Kotlin Programming By Example
- Iyanu Adelekan
- 136字
- 2021-08-27 20:00:09
Return values
A return value—as the name implies—is the value that a method returns. Functions in Kotlin can return values upon execution. The type of the value returned by a function is defined by the function's return type. This is demonstrated in the following code snippet:
fun returnFullName(firstName: String, surname: String): String {
return "${firstName} ${surname}"
}
fun main(args: Array<String>) {
val fullName: String = returnFullName("James", "Cameron")
println(fullName) // prints: James Cameron
}
In the preceding code, the returnFullName function takes two distinct strings as its input parameters and returns a string value when called. The return type has been defined in the function header. The string returned is created via string templates:
"${firstName} ${surname}"
The values for first name and last name are interpolated into the string of characters.
推薦閱讀
- Mastering JavaScript Functional Programming
- Python快樂編程:人工智能深度學習基礎
- Python程序設計(第3版)
- Java加密與解密的藝術(第2版)
- Expert Android Programming
- ArcGIS By Example
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- 軟件品質之完美管理:實戰經典
- Visual C++開發入行真功夫
- UML2面向對象分析與設計(第2版)
- TypeScript 2.x By Example
- Android移動應用開發項目教程
- SAP Web Dynpro for ABAP開發技術詳解:基礎應用
- PostgreSQL 12 High Availability Cookbook
- 算法超簡單:趣味游戲帶你輕松入門與實踐