In Kotlin, if
, try
and others are expressions (so they do return a value) rather than (void) statements.
So, for example, Kotlin does not have Java's ternary Elvis Operator, but you can write something like this:
val i = if (someBoolean) 33 else 42
Even more unfamiliar, but equally expressive, is the try
expression:
val i = try {
Integer.parseInt(someString)
}
catch (ex : Exception)
{
42
}