只有当美元符号后面的字符串内容可能被误解为字符串插值条目时,才需要转义。
示例:
fun example() {
"The price today is \$10. The price tomorrow will be ${'$'}20."
}
快速修复会将所有可安全替换的转义美元字符转换为常规美元字符:
fun example() {
"The price today is $10. The price tomorrow will be $20."
}