is there any specific reason for that
# getting-started
f
is there any specific reason for that
d
=
is a statement and not an expression.
So
b = 3
doesn't evaluate to any value.
This decision was made mostly to allow for named parameters.
Copy code
var b = 4
fun max(a: Int, b: Int): Int = TODO()

max(a = 2, b = 5)
This would be ambiguous to the compiler, if
=
was an expression.
f
ok thank you
a
It also prevents accidental assignment.
The following is valid Java, but probably not what you meant:
Copy code
boolean isSomeCondition = checkSomeCondition();
        if (isSomeCondition = checkSomeOtherCondition()) {
            // isSomeCondition now has the 2nd value:  it was accidentally assigned, instead of just compared
        }
In Kotlin, this accidental assignment doesn't compile because
if()
needs an expression.
f
yes that makes sense
thanks