Bernhard
03/14/2025, 8:06 AMwhen(enum) {
CASE1, CASE2, CASE3 if otherCondition ->
}
Youssef Shoaib [MOD]
03/14/2025, 8:18 AMwhen(enum) {
in listOf(CASE1, CASE2, CASE3) if otherCondition ->
}
Bernhard
03/14/2025, 8:26 AMKlitos Kyriacou
03/14/2025, 10:51 AMin listOf(CASE1, CASE2, CASE3)
, Kotlin will:
1. Allocate an array
2. Allocate a List
and wrap the array
3. Call contains
The performance hit may not be noticeable so it's worth profiling.Bernhard
03/14/2025, 10:52 AMBernhard
03/14/2025, 10:54 AMBernhard
03/14/2025, 10:54 AMKlitos Kyriacou
03/14/2025, 10:56 AMin arrayOf
instead, but it's probably not worth it, as listOf
seems to be more idiomatic. On the other hand, if it was primitive types, it would be better to use in intArrayOf
to avoid boxing.Bernhard
03/14/2025, 10:57 AMBernhard
03/14/2025, 10:57 AMMichael de Kaste
03/17/2025, 8:44 AMin SET_OF_ENUMS if(condition) ->