https://kotlinlang.org logo
#feed
Title
# feed
m

Milan Hruban

05/04/2020, 11:28 AM
Do you guys actually use the
3. The Smart-Cast Elvis Operator approach
? (You have two number threes btw). I understand that it's less characters, but you still have to translate it to the good old
if
when reading the code, right?
🙏 1
e

elye

05/04/2020, 11:39 AM
I think I can read
couldBeNullMesage ?: return
… It’s almost like reading Java ternary…
trueOrFalse ? doOnTrue : doOnFalse;
m

Milan Hruban

05/04/2020, 12:00 PM
hmm that explains it..I hate ternary operator 😄
😉 1
t

thana

05/04/2020, 12:05 PM
i have used this feature from time to time, yes
👍 1
e

elect

05/04/2020, 12:52 PM
yep, I totally agree, I think Swift should have gone by automatically return if null. The point of writing
guard
is pretty useless otherwise
👍 2
s

Steve

05/04/2020, 4:53 PM
you may wish to do something else before returning, like logging or throwing an error
e

elect

05/04/2020, 5:01 PM
and then you would write
e

elye

05/05/2020, 9:25 AM
@Steve, to print something, just use
Copy code
couldBeNullMesage ?: run { println("hello there"); return }
7 Views