How can I make a line break (line continuation) in Kotlin
1 answer
There is no line continuation symbol in Kotlin. Since its grammar allows spaces between almost all characters, you can simply break the statement:
val text = "This " + "is " + "a " +
"long " + "long " + "line"
However, if the first line of the statement is valid, it doesn't work :
val text = "This " + "is " + "a "
+ "long " + "long " + "line" // syntax error
To avoid such problems when breaking long statements across multiple lines, you can use parentheses:
val text = ("This " + "is " + "a "
+ "long " + "long " + "line") // no syntax error
See Kotlin grammar for more information .
+10
source to share