2

I recently faced a problem regarding interoperability between Java/Kotlin for suspend functions. See my question: How to Override a suspend function in java class. Both the answers seem to agree on suspend functions not completely interoperable.

So, this got me wondering; in what other features are Java/Kotlin not interoperable?

Abbas
  • 3,529
  • 5
  • 36
  • 64
  • 3
    While this is an interesting question, it's not a very good fit for this site because it's asking for a list (so there's no single right answer). In general, though: practically anything you can do in Java can be done in Kotlin, and Kotlin can interoperate with practically any existing Java code — but the reverse doesn't always hold where Kotlin introduces new features. As you say, it's hard for Java to implement Kotlin suspend functions. Similarly, you might not be able to call inline functions from Java… – gidds May 04 '22 at 22:17
  • 1
    …you won't be able to name parameters, and might not be able to omit them to get their default values. You won't be able to use operators that are overloaded in Kotlin (though you should be able to call their named methods). And so on. Kotlin generally does its best to allow Java interoperability — sometimes by the use of annotations such as `@JvmStatic` — but there's a limit to what it can reasonably do. – gidds May 04 '22 at 22:17
  • 4
    For more info see [these](https://kotlinlang.org/docs/java-interop.html) [sections](https://kotlinlang.org/docs/java-to-kotlin-interop.html) of the language docs. – gidds May 04 '22 at 22:19
  • @gidds while it is true that this question maybe a little open ended. The aim was to provide a central location for these limitations. – Abbas May 05 '22 at 13:45
  • While the reference links help out with inter-op issues and addresses almost all of them, they fail to provide examples such as suspend functions where inter-op is either actively discouraged or not supported. IMO a central resource providing even an incomplete list would be helpful, in general. – Abbas May 05 '22 at 13:48
  • However, you and other moderators can still vote to close this question if you believe this question is not suited for this site. – Abbas May 05 '22 at 13:49

0 Answers0