Nullable assigner?

The main reason why I posted this is that I found a lot of the following code samples:

if(a != null) a = func()
a!!.exec()

I wanted to refactor this, but right now I need to check four things before I can refactor:

  • Is setA or func expensive?
  • Does setA handle assigning the same variable to it well?
  • Does func have side effects?
  • Does a need to be set, before calling exec on it.

When one of these reasons is true, only the nullable assigner or where it is mapped to is possible.

I will search for founded reasons of this and then I will post it here.

2 Likes