semicolon-inference

When is semicolon mandatory in scala?

寵の児 提交于 2020-02-24 14:41:13
问题 I am learning how to program in Scala and was being told that semicolon is optional in Scala. So with that in mind, I tried with the following nested block of code which does not have semi colon. However, it throws an error in the Scala REPL scala> { val a = 1 | {val b = a * 2 | {val c = b + 4 | c} | } | } <console>:17: error: Int(1) does not take parameters {val b = a * 2 And the sample with semi colon worked perfectly fine. scala> { val a = 1; | { val b = a*2; | { val c = b+4; c} | } | }

When is semicolon mandatory in scala?

心已入冬 提交于 2020-02-24 14:39:24
问题 I am learning how to program in Scala and was being told that semicolon is optional in Scala. So with that in mind, I tried with the following nested block of code which does not have semi colon. However, it throws an error in the Scala REPL scala> { val a = 1 | {val b = a * 2 | {val c = b + 4 | c} | } | } <console>:17: error: Int(1) does not take parameters {val b = a * 2 And the sample with semi colon worked perfectly fine. scala> { val a = 1; | { val b = a*2; | { val c = b+4; c} | } | }