im trying to understand the difference between the following two pieces of code in kotlin:
myVar?.let { print(it) } ?: run { print("its null folks") }
vs
myVar?.let { print(it) } ?: print("its null folks")
are they equivalent ? is run just so we can use a block of code and the the other is for just a single statement ?
Yes, they are equivalent. run
allows you to use multiple statements on the right side of an elvis operator; in this case there's only one, so run
is not needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With