- Kotlin Programming Cookbook
- Aanand Shekhar Roy Rashi Karanpuria
- 96字
- 2025-04-04 17:32:31
How it works...
The use of String template with a variable name is quite straightforward. Earlier, we used to concatenate the strings, but now we can just specify the variable with the $ symbol before it.
When the string template is used as an expression, the expression inside the ${..} is evaluated first and the value is concatenated with the string. In the preceding example (String template with raw string), the ${if (a > b) a else b} expression is evaluated and its value, that is 6, is printed with the string.