In kotlin it could use ?.let
to only run the code block if the variable is not null. If there are multiple variables it could be done like:
v1?.let { value1 ->
v2?.let { value2 ->
doSomething(value1, value2)
}
}
compare with
if (v1 != null && v2 != null){
doSomething(v1, v2)
}
Is there a better way to do it?