Skip to content

Commit

Permalink
Add usage of STAR (#1572)
Browse files Browse the repository at this point in the history
* Add usage of STAR

* Update link
  • Loading branch information
Omico authored May 26, 2023
1 parent 1a02180 commit 2ba85bf
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ KotlinPoet has classes for building each of these:

```kotlin
import com.squareup.kotlinpoet.ParameterizedTypeName.Companion.parameterizedBy
import com.squareup.kotlinpoet.STAR

val hoverboard = ClassName("com.mattel", "Hoverboard")
val list = ClassName("kotlin.collections", "List")
Expand All @@ -339,8 +340,15 @@ val printThings = FunSpec.builder("printThings")
.addParameter("things", producerArrayOfThings)
.addStatement("println(things)")
.build()

val printKClass = FunSpec.builder("printKClass")
.addParameter("kClass", KClass::class.asClassName().parameterizedBy(STAR))
.addStatement("println(kClass)")
.build()
```

The `STAR` is represented as `*` in KotlinPoet. You can find more in the [KDoc][kdoc].

KotlinPoet will decompose each type and import its components where possible.

```kotlin
Expand All @@ -351,6 +359,7 @@ import com.misc.Thing
import kotlin.Array
import kotlin.collections.ArrayList
import kotlin.collections.List
import kotlin.reflect.KClass

class HelloWorld {
fun beyond(): List<Hoverboard> {
Expand All @@ -364,6 +373,10 @@ class HelloWorld {
fun printThings(things: Array<out Thing>) {
println(things)
}

fun printKClass(kClass: KClass<*>) {
println(kClass)
}
}
```

Expand Down

0 comments on commit 2ba85bf

Please sign in to comment.