ShootingStar
12/17/2019, 1:05 PMMate
12/17/2019, 1:06 PMIvan Kubyshkin [JetBrains]
12/17/2019, 1:06 PMShootingStar
12/17/2019, 1:07 PMMikael Alfredsson
12/17/2019, 1:26 PM@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
@Test
fun testShortCircuit() {
var a = 0;
fun incA(): Boolean {
a++;
return true
}
if (incA() || a == 0) {
// is a 0 or 1?
println(a)
}
}
Alowaniak
12/17/2019, 2:22 PMSafe 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