Assign value to variable only if is not null – Kotlin

Another solution if You don’t want to return from function just yet:

x?.let{ y = it }

Which checks if x is non-null then passes it as the only parameter to the lambda block.

This is also a safe call in case your x is a var.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)