As far as I can see, the only way to use the elvis operator is the syntax:
foo = bar ?: return
I was curious if anyone had come up with a way to enable logging, since returns are usually used (at least in my experience) when something doesn't behave as expected.
However, the following syntax is invalid:
foo = bar ?: { Log.e(TAG, "Some error occurred.") return }
Of course, I could just do the following:
foo = bar if (foo == null) { Log.e(TAG, "Some error occurred.") return }
but is there a way to enable logging using the Elvis operator?
source share