By the way, you'd instead use switch() for the second one in other languages, or when they don't have it - hash tables, e.g. python, by making use of .get() method on dictionary which will either return the match or default value, and this behaviour is identical to switch. But I get the point.
The switch statement doesn't work with any object thoug let alone expressions (wich do work on kotlins "when"). It just accepts basic types, String and Enum - at least in the version available on Android. I used java on android for many years privately (and on github) and since kotlin came out I have never looked back. It's pretty amazing that Kotlin is bytecode compatible with the old jvm used in android and yet has so many advanced features. I freakin love it!
View all comments
Show parent comment
0
u/PurpleIcy Sep 17 '18 edited Sep 17 '18
I see, I'll check it out, thanks.
By the way, you'd instead use switch() for the second one in other languages, or when they don't have it - hash tables, e.g. python, by making use of .get() method on dictionary which will either return the match or default value, and this behaviour is identical to switch. But I get the point.