Your Site Title

kotlin reflection

dependencies {
    implementation("org.jetbrains.kotlin:kotlin-reflect:1.7.20")
}

<dependencies>
  <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-reflect</artifactId>
  </dependency>
</dependencies>

references

兼容Java反射

kotlin使用kotlin.reflect.jvm兼容java反射

import kotlin.reflect.jvm.*

class A(val p: Int)

fun main() {
    println(A::p.javaGetter) // prints "public final int A.getP()"
    println(A::p.javaField)  // prints "private final int A.p"
}

Reference