Hacker News new | ask | show | jobs
by stewbrew 3149 days ago
"One thing I found out is that you really have to write a library in Java if you want it to be used in both Java and Kotlin. Java -> Kotlin is effectively one-way interop."

Could you please explain this.

1 comments

I think it means that a library written in Kotlin is difficult or impossible to use from Java.
Not really true from my experience. For example, here's a Markdown library written in Kotlin that you can use with a plain Java interface: https://github.com/valich/intellij-markdown
No no no no. Kotlin provides a lot of tools to make your library usable from Java and it works.
You have to write your Kotlin anticipating it'll be called from Java though (e.g. by using SAM interfaces instead of function types for your arguments)
This does not mean that it is a one-way interop. When you write it the right way, it will work from Java.
Is Kotlin's function not an SAM interface? I'm pretty sure Scala's is.