建议使用字符串模板,因为这样会使代码更容易读取。
示例:
fun example() {
val capitals = mapOf("France" to "Paris", "Spain" to "Madrid")
for ((country, capital) in capitals) {
print(capital + " is a capital of " + country)
}
}
在应用快速修复后:
fun example() {
val capitals = mapOf("France" to "Paris", "Spain" to "Madrid")
for ((country, capital) in capitals) {
print("$capital is a capital of $country")
}
}