79179698

Date: 2024-11-12 03:28:43
Score: 0.5
Natty:
Report link

Another approach would be using when with val

Example:

when(val a = b.value) {
    null -> {}
    else -> {} //Value of a can be accessed inside else block as not-null
}

A drawback with this approach is even if you don't want to run anything when value is null, you must specify null case with empty block.

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: Nabeel