What is the meaning in this context?
# announcements
s
What is the meaning in this context?
s
Thank you
m
This is quite important if you deal with functions with side effects (which you should avoid as much as possible anyway)
Copy code
@Test
    fun testShortCircuit() {

        var a = 0;
        fun incA(): Boolean {
            a++;
            return true
        }
        if (a == 0 || incA()) {
            // is a 0 or 1?
            println(a)
        }
    }
compared to
Copy code
@Test
    fun testShortCircuit() {

        var a = 0;
        fun incA(): Boolean {
            a++;
            return true
        }
        if (incA() || a == 0) {
            // is a 0 or 1?
            println(a)
        }
    }
a
I think the
Safe call short-circuits
is a bit misleading? Because
null?.let{}.let{println("hi")}
still prints hi (which I think it ideally wouldn't because then you wouldn't have to chain null-safe operator for non-nullable properties) But I guess it makes sense in the sense that the direct right-hand part isn't evaluated