andrzej
01/07/2020, 4:14 PMemptySet()
2. setOf()
I know these two are equivalent (implementation is identical), but what is the more idiomatic Kotlin way? Is there any reason why 2 solutions exist for the same issue? I know this question might sound silly but we have a code base where both ways are used and want to get rid of one of them once and for all.Hanno
01/07/2020, 4:18 PMMichael de Kaste
01/07/2020, 4:20 PMandrzej
01/07/2020, 4:20 PM@kotlin.internal.InlineOnly
public inline fun <T> setOf(): Set<T> = emptySet()
Michael de Kaste
01/07/2020, 4:21 PMmarstran
01/07/2020, 4:21 PMsetOf
creates a read only set, so it won't get bigger in the future.Michael de Kaste
01/07/2020, 4:22 PMMichael de Kaste
01/07/2020, 4:24 PMDico
01/07/2020, 4:37 PMsetOf()
in general.Dico
01/07/2020, 4:41 PMval someSpecialStrings = setOf(
)
Dico
01/07/2020, 4:42 PMDaniel
01/07/2020, 7:01 PMsetOf(first: T, vararg ensuing: T)
Dont know why they decided against it.
Other than that: emptySet() is most likely a fallback of some sort. So best be explicit and call it emptySet(). The empty immedeately conveys the meaning
``````