I'm studying Scala and trying to use it in my recent projects. And problems come. Here's one of my problem about necessity of semicolons. This is my example:
var str = "123.4"
var d = str toDouble
if(d > 10)
println("Larger than 10")
These codes cannot be compiled. Because if(d > 10) println("Larger than 10")
returns value and compiler thinks this value is a parameter of toDouble
method. However, toDouble
doesn't have a parameter. This causes error.
The easiest way to solve this is adding a semicolon at the end of line 2. Just like this:
var str = "123.4"
var d = str toDouble;
if(d > 10)
println("Larger than 10")
This confused me and I thought I don't need semicolons at all as I won't put two statements at same line. It makes me uncomfortable that some lines end with semicolon while the others don't. Also, does it makes sense?