Adam Arold Adam Arold - 1 year ago 85
Java Question

How can I call Kotlin methods with reified generics from Java?

I have the following method in Kotlin:

inline fun <reified T> foo() {


If I try to call this from Java like this:;

OR like this:


I get the following error:

java: foo() has private access in MyClass

How can I call the
method from Java?

Answer Source

There's no way to call Kotlin inline functions from Java because they must be transformed and inlined at the call sites (in your case, T should be substituted with the actual type at each call site, but there's much more compiler logic for inline functions than just this), and the Java compiler is, expectedly, completely unaware of that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download