'The Scala ternary operator syntax'에 해당되는 글 1건

  1. 2014.03.28 The Scala ternary operator syntax
00.scala2014. 3. 28. 12:56
반응형

Scala FAQ: What is the Scala ternary operator syntax?

In other programming languages there is a definite, unique ternary operator syntax, but in Scala, the ternary operator is just the normal Scala if/else syntax:

if (i == 1) x else y

The beauty of this is (a) it is just the normal if/else syntax, so you don't have to remember something else, and (b) it's easy to read.

Also, as you can see from this example, you can use the Scala ternary operator syntax on the right hand side of the equation, as you might be used to doing with Java:

val a = if (i == 1) x else y;

Contrast the readability of the Scala ternary syntax with the Java ternary operator syntax:

i == 1 ? x : y


Posted by 1010