what benefits does `emptyList<String>()` hav...
# getting-started
a
what benefits does
emptyList<String>()
have compared to
listOf<String>()
? Thread in Slack Conversation
r
a
is this case for a class, a module, or a package?
r
What do you mean?
a
this same object need to be in a class, a module, or a package?
r
I'm sorry, I still don't understand what you're asking. The instance returned by
emptyList
is a singleton, so there is only one. Not one per package, or one per module, or one per class, just one total.
r
listOf<String>()
is an alias to `emptyListString()`:
public inline fun <T> listOf(): List<T> = emptyList()
So in practice there is no difference, they return exactly the same instance.
👍 3
a
@Rob Elliot where to see your code
public inline fun <T> listOf(): List<T> = emptyList()
. kotlin source code?
Or just hyperlink through to it in your IDE
a
good. have you read all kotlin source code? @Rob Elliot
k
I don't think anyone has read all of the Kotlin source code! The way to check is to first go to the documentation. If you're not sure, just do a Google search like
site:<https://kotlinlang.org/api> listOf
- then click on the relevant link, which takes you to https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/list-of.html and from there, click on the "source code" link.
👍 2