-1
我在scala中有一部分代碼,它現在正在拋出錯誤。錯誤消息說重新分配給val。下面的代碼片段:行word = word.trim()
在scala中使用trim關鍵字
private def tokenize(line: String) {
val words = line.split("\\s+")
for (word <- words) {
if (word == null) //continue
word = word.trim()
if (word.length == 0) //continue
if (word == "WRITEINT") {
addLast(new Token(TokenType.WRITEINT, word))
,但此錯誤apprears如何擺脫這種錯誤的?
'斯卡拉val's是不可改變的。你只能給他們分配一次。如果你想要可變狀態,你可以使用'var'。然而,無論如何避免可變狀態通常是一個好主意,所以你可能想重新考慮你的代碼。 – toniedzwiedz 2015-02-17 23:19:48
很多那些'if's是不必要的。 – 2015-02-18 00:45:36