Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to comment kotlin file as a class for java

Tags:

java

kotlin

In kotlin xxx.kt:

@file:JvmName("Utils")
fun staticFunc()

In java xxx.java:

Utils.staticFunc()

But in java we can't see comment of class Utils because class Utils is not exist(actually it is xxx.kt), How to comment xxx.kt let java user can see comment of class Utils?

like image 335
wozuiqiangdeaoyi Avatar asked Jan 30 '26 21:01

wozuiqiangdeaoyi


1 Answers

This is not supported. The Utils class does not exist from the Kotlin point of view, it's only produced for JVM interop, so there is no way to provide documentation for it.

If you need to provide documentation to Java callers, use an object instead:

/**
 * My utility functions.
 */
object Utils {
    fun staticFunc() { ... }
}
like image 91
yole Avatar answered Feb 01 '26 14:02

yole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!