val method = result.jsonObject?.get("result")?.asString
?: throwInsertionError(result)
return when (method) {
c
Czar
05/06/2019, 11:28 AM
Hm... I'd rewrite it as
Copy code
private fun ResultType.jsonResultAsString() = jsonObject?.get("result")?.asString
?: throwInsertionError(result)
//...
return when (val method = result.jsonResultAsString()) {
Where
val method =
part is only needed if you're using
method
in branches' bodies
Czar
05/06/2019, 11:33 AM
The inspection you mention has been useful to me on numerous occasions, so it is use-case dependent. Sometimes the refactoring I suggested above is not useful or possible, so, yeah, on those occasions the inspection is not welcome. But in general if I see that, it is usually and indication that relevant code can be polished further.
m
Mike
05/06/2019, 12:06 PM
and depending on what happens in the
when (method)
, IntelliJ may be suggesting that it all get rolled into one