Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

391
Views
Convert java Class<> to kotlin's KClass<>

like I hava a kotlin function:

object KotlinFunc {
    @JvmStatic
    fun create(mycls: KClass<*>) {...}
}

I want to invoke this function in java code, but this not working:

public void javaFunc() {
   KotlinFunc.create(MyClass.class)
}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

It is possible by using calling the getKotlinClass function in Java:

kotlin.jvm.JvmClassMappingKt.getKotlinClass(MyClass.class);

you can invoke your function like this:

kotlin.reflect.KClass<MyClass> kClass = kotlin.jvm.JvmClassMappingKt.getKotlinClass(MyClass.class);
KotlinFunc.create(kClass);

and make sure that kotlin-reflect is in your classpath, e.g.:

with Gradle Kotlin:

dependencies {
    ...
    implementation(kotlin("reflect"))
    ...
}

with Gradle Groovy:

dependencies {
    ...
    implementation 'org.jetbrains.kotlin:kotlin-reflect'
    ...
}
over 4 years ago · Santiago Trujillo Report

0

You can do it this way using the standard library:

KClass kotlinClass = Reflection.createKotlinClass(MyClass.class);
KotlinFunc.create(kotlinClass)
over 4 years ago · Santiago Trujillo Report

0

In Kotlin Class has an extension property .kotlin.

It is declared in kotlin.jvm.JvmClassMapping.kt (source code).

In Java it will look as a static method <T> KClass<T> getKotlinClass(Class<T>) in the class kotlin.jvm.JvmClassMappingKt.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!