<https://medium.com/@elye.project/kotlins-elvis-be...
# feed
m
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
I think I can read
couldBeNullMesage ?: return
… It’s almost like reading Java ternary…
trueOrFalse ? doOnTrue : doOnFalse;
m
hmm that explains it..I hate ternary operator 😄
😉 1
t
i have used this feature from time to time, yes
👍 1
e
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
you may wish to do something else before returning, like logging or throwing an error
e
and then you would write
e
@Steve, to print something, just use
Copy code
couldBeNullMesage ?: run { println("hello there"); return }