• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

426
Views
Kotlin methods accepting inline classes as parameters - how access from Java?

Let's say I have:

inline class Email(value: String)

and

fun something(email: Email)

now if I want to call something() from Java I can't. Because any method that is accepting an inline class as a parameter is "mangled" (more about this here: https://kotlinlang.org/docs/reference/inline-classes.html#mangling) As far as I understood mangling renames the method name to include a "-" that's an invalid character in Java, so the method is practically invisible from Java perspective. That's intentional probably because of strong type safety. But I really need to make the method callable from both Java and Kotlin. Do you know some workaround?

almost 3 years ago · Santiago Trujillo
2 answers
Answer question

0

According to the KEEP that is used to discuss and plan inline classes, this is not currently possible (writing as of 1.3.11):

We'll compile function compute(UInt) to compile-<hash>(Int), where <hash> is a mangling suffix for the signature. Now it will not possible to call this function from Java because - is an illegal symbol there, but from Kotlin point of view it's a usual function with the name compute. [Emphasis mine]

Keep in mind that inline classes are experimental and subject to change, so perhaps in a future release this will be possible. I did try annotating this with @JvmName and that is also not supported.

almost 3 years ago · Santiago Trujillo Report

0

Please, manually disable Kotlin names mangling with @JvmName

@JvmName("something")    
fun something(email: Email)

See docs for more details

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error