Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a top level kotlin function in java?

Tags:

java

kotlin

Assume a kotlin function is defined outside of a class as top level function.

Util.kt:

class Util {
   fun bar()
}
fun foo(){}

How can I call method foo() in Java?

like image 257
Chriss Avatar asked Dec 03 '22 18:12

Chriss


1 Answers

foo will be compiled to a static function in a class whose name is that of the Kotlin source file with the suffix Kt - so in this case, you can say UtilKt.foo().

like image 187
Aasmund Eldhuset Avatar answered Dec 07 '22 22:12

Aasmund Eldhuset