I wonder, why can't I compile this one:
class MyClass{
override def toString = "123:" + if (true) "456" else "789"
//error: illegal start of simple expression
}
Try this:
override def toString = "123:" + (if (true) "456" else "789")
(Console println throw new RuntimeException).pedrofurla is right. With your expression the compiler tries to mix the string with the if and fails. Using parenthesis you eliminate ambiguity in your expressions.
class MyClass{
override def toString = "123:" + (if (true) "456" else "789")
}
I found this simple online service where you can test your scala expressions: http://www.simplyscala.com/