2

While looking at examples of Kotlin code I cam across this:

fun main(args: Array<String>) { val myList = List(3) {it + 1} println(myList) } 

I understand what it does, but I didn't know a List could be constructed this way. When I reference the documentation (https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/-list/index.html) to see other possible ways to construct a List, I don't see any constructors at all. I can only assume I'm not looking in the right spot.

How do I go about properly reading documentation for Kotlin? Shouldn't everything pertaining to a List be contained in one place?

1 Answer 1

3

Since List is only an interface, it cannot have any constructors - it's a global function.

Most IDEs (like IntelliJ) should let you "ctrl+left click" or otherwise navigate to the source.

This is the related package: kotlin.collections.

And function you refer to: List.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.