Vidyalelo
Computer Science · Q253

Kotlin Programming MCQ for Competitive Exams, Interviews, and Certifications

Engineering and GATE · Computer Science · question 253

Q253

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

Answer: Option D

Solution

Answer: Option D
No explanation is given for this question Let's Discuss on Board