• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ELVIS operator

jjude

Lurker
How can i change these ELVIS operator?

val tag = intent.getParcelableExtra<Tag>(NfcAdapter.EXTRA_TAG)
if (tag == null) return

val ndef = Ndef.get(tag)
if(ndef == null) return

val raws = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES)
if(raws == null) return
 
Elvis is in fact alive and well. Here's the code equivalent

Code:
val l = b?.length ?: -1

Notice the Elvis quiff?

Although in answer to the OP, the Elvis operator isn't really applicable to your code, as all you're doing is checking for null. Besides, Kotlin has a handy automatic null safety check operator.
 
Elvis is in fact alive and well. Here's the code equivalent
Although in answer to the OP, the Elvis operator isn't really applicable to your code, as all you're doing is checking for null. Besides, Kotlin has a handy automatic null safety check operator.

Android Studio encourages me to move if to Elvis method
but i don't need to care about it
 
Back
Top Bottom