Is this more readable?

We have been picking up Kotlin in our team for about 3 months now. We still have projects in Java as well so we are using both languages depending on the project.

Recently I wrote this:

fun someMethod(dataMap: Map<String, Any>): SomeEnum { if (dataMap["isPossible"]!! as Boolean) { return if (dataMap["isAutomated"]!! as Boolean) VALUE1 else VALUE2 } return VALUE3 } It checks if the map contains the key “isPossible” and is true. Afterwards it check if the dataMap contains key “isAutomated” and is true. Depending on that it returns an enum value.

My tech lead told me this is not the kotlin way and I should write it like this:

fun someMethod(dataMap: Map<String, Any>): SomeEnum = when { dataMap["isPossible"]!! as Boolean -> when { dataMap["isAutomated"]!! as Boolean -> VALUE1 else -> VALUE2 } else -> VALUE3 }

I honestly can’t see the advantage of using the second approach. For me it is just harder to read. Am I missing something here? Or do I just need to become more fluent in the language?

Edit: typo

submitted by /u/garagepoort2
[link] [comments]