https://kotlinlang.org logo
Title
u

user

07/25/2022, 10:41 AM
Kotlin and ?.let: how to choose variants of variable's fields? I have a class: class Clazz( val name: String?, val value0: String, val value1: String?, val value2: String ) I want to print value0 if we have non-null name. But if name is null, then i want return value1 only if it is not null. if it is, return value2. i do it in let way: val result = clazz.name?.let { return clazz value0 } ?: run { value1 ?: value2 } but i think it is quite shitty code and it could be...