Examveda

Which line of code is a shorter, more idiomatic version of the displayed snippet?
val len: Int = if (x != null) x.length else -1

A. val len = x?.let{x.len} else {-1}

B. val len = x!!.length ?: -1

C. val len:Int = (x != null)? x.length : -1

D. val len = x?.length ?: -1

Answer: Option D


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

A. A new version of Java.

B. A JavaScript framework.

C. A statically-typed programming language for the JVM, Android, and browser.

D. A database management system.