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

String interpolation

What if we would like to actually print those results? 

First, as you may have already noticed, in one of the examples above, Kotlin provides a nifty println() standard function that wraps the bulkier System.out.println() from Java.

But, more importantly, as in many other modern languages, Kotlin supports string interpolation using the ${} syntax. Following on from the example before:

println("I would suggest: ${suggestGift(10)} ")

The preceding code would print: 

I would suggest: a book

If you're interpolating a variable, and not a function, curly braces could be omitted: 

val gift = suggestGift(100)
println("I would suggest: $gift ")

This would print the following output:

I would suggest: a guitar
主站蜘蛛池模板: 定结县| 崇阳县| 台中县| 黄龙县| 那坡县| 五大连池市| 沛县| 腾冲县| 新巴尔虎右旗| 景泰县| 凌海市| 长顺县| 买车| 白城市| 平度市| 柘荣县| 金堂县| 周至县| 景宁| 喀喇沁旗| 蛟河市| 四平市| 阜平县| 安达市| 通河县| 开鲁县| 彭阳县| 镇远县| 和平县| 冷水江市| 鄂托克前旗| 集安市| 平利县| 绥阳县| 庆云县| 永福县| 灵石县| 富民县| 泰兴市| 和平区| 林周县|