Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What is the correct way of defining a Kotlin string that includes the characters for declaring a template substitution, but not have this evaluated as a template?

For example: "${something}" just treated as an ordinary string.

I would like to use the Spring value annotation:

@Value("${some.property}) lateinit var foobar : String?
question from:https://stackoverflow.com/questions/33461403/escape-something-in-a-kotlin-string

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
86 views
Welcome To Ask or Share your Answers For Others

1 Answer

This works for me:

val s = "${foo}"
println("s = ${s}") // prints s = ${foo}

The documented way also works fine:

val s = "${'$'}{foo}"
println("s = ${s}") // prints s = ${foo}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...