https://kotlinlang.org logo
#getting-started
Title
# getting-started
a

anlex N

03/26/2024, 6:07 AM
what benefits does
emptyList<String>()
have compared to
listOf<String>()
? Thread in Slack Conversation
r

Ruckus

03/26/2024, 6:08 AM
a

anlex N

03/26/2024, 6:14 AM
is this case for a class, a module, or a package?
r

Ruckus

03/26/2024, 6:15 AM
What do you mean?
a

anlex N

03/26/2024, 6:16 AM
this same object need to be in a class, a module, or a package?
r

Ruckus

03/26/2024, 6:20 AM
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

Rob Elliot

03/26/2024, 8:10 AM
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

anlex N

03/26/2024, 8:18 AM
@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

anlex N

03/26/2024, 8:44 AM
good. have you read all kotlin source code? @Rob Elliot
k

Klitos Kyriacou

03/26/2024, 10:25 AM
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