gentlemanRabbit
gentlemanRabbit

Reputation: 315

Properly Reading and Understanding Documentation

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?

Upvotes: 2

Views: 67

Answers (1)

Pawel
Pawel

Reputation: 17268

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.

Upvotes: 3

Related Questions