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

Marcello Galhardo

04/06/2021, 4:30 PM
Hey folks, in your opinion what is more "Kotlin Idiomatic" way for guard clauses? 🤔
1️⃣ 4
2️⃣ 6
e

ephemient

04/06/2021, 4:37 PM
smart casting will only work if
keyPair
is a data class defined in the same module
(and
keyPair
is a local
val
without custom getter, etc. the usual rules for smart casting)
m

Marcello Galhardo

04/06/2021, 4:41 PM
@ephemient this is not a problem for my case but good catch, I completely forgot that. 🤔
m

Milan Hruban

04/07/2021, 8:44 AM
I would use 2️⃣ if I wanted to assign it to variable, e.g:
Copy code
val pub = keyPair.public ?: return null
val priv = keyPair.private ?: return null
otherwise 1️⃣ .
👍 3
e

ephemient

04/08/2021, 4:49 AM
the elvis operator are standard kotlin style, get used to them.
👍 2
6 Views