2017-05-25 50 views

回答

10

有用於科特林續行沒有符號。作爲其語法允許幾乎所有的符號之間的空間,你可以打破聲明:

val text = "This " + "is " + "a " + 
     "long " + "long " + "line" 

但是,如果語句的第一行是一個有效的聲明,它不會工作

val text = "This " + "is " + "a " 
     + "long " + "long " + "line" // syntax error 

爲了避免這樣的問題,打破多行長語​​句時,你可以使用括號:

val text = ("This " + "is " + "a " 
     + "long " + "long " + "line") // no syntax error 

更多的Infor請參閱Kotlin Grammar