在普通字符串中,我可以${variable}用反斜杠转义:
"You can use \${variable} syntax in Kotlin."
是否可以在字符串文字中做同样的事情?反斜杠不再是转义字符:
// Undesired: Produces "This \something will be substituted.
"""This \${variable} will be substituted."""
到目前为止,我看到的唯一解决方案是字符串连接,这非常难看,以及嵌套插值,这开始变得有点荒谬:
// Desired: Produces "This ${variable} will not be substituted."
"""This ${"\${variable}"} will not be substituted."""