July 2018
Intermediate to advanced
400 pages
12h 14m
English
You have seen that a string can be built up with the values of variables and even the results of conditional expressions. Kotlin features string templates to aid in this common need and, again, make your code more readable. Templates allow you to include the value of a variable inside a string’s quotation marks. Update the player status display code to use string templates, as shown below:
Listing 3.11 Using a string template (Game.kt)
fun main(args: Array<String>) {
...
// Player status
println(name + " " + healthStatus)
println("$name $healthStatus")
}
You added the values of name and healthStatus to the player status display string by prefixing each with $. This special symbol indicates to Kotlin that ...
Read now
Unlock full access