From 2ba85bf42ff99536d7cea06a4ad5d16944538f96 Mon Sep 17 00:00:00 2001 From: Omico Date: Fri, 26 May 2023 02:14:10 -0700 Subject: [PATCH] Add usage of STAR (#1572) * Add usage of STAR * Update link --- docs/index.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/index.md b/docs/index.md index 4b8ec1a19f..5879c3e523 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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") @@ -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 @@ -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 { @@ -364,6 +373,10 @@ class HelloWorld { fun printThings(things: Array) { println(things) } + + fun printKClass(kClass: KClass<*>) { + println(kClass) + } } ```