Is there a clean way in Kotlin to assign a value to a variable only if the value is not null?
My example is:
if(x != null)
y = x
I found a solution like
y = x? : return
but I don't understand if this does what I want and how this operator works.
var y: Int? = 0 set(x: Int?) { if (x != null) field = x }yis probably a non-null field, hence the nullability check before assignment.