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

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.

主站蜘蛛池模板: 琼海市| 内黄县| 大丰市| 利津县| 抚州市| 井冈山市| 龙岩市| 长春市| 静宁县| 盐津县| 久治县| 钟祥市| 秀山| 安化县| 金坛市| 右玉县| 织金县| 黎川县| 原平市| 商南县| 虎林市| 陆丰市| 扎兰屯市| 隆昌县| 大城县| 嘉善县| 镇安县| 泰来县| 文昌市| 高陵县| 吉林省| 连江县| 南江县| 林口县| 万安县| 泸州市| 嘉定区| 松原市| 西乌珠穆沁旗| 广元市| 宣威市|