Calling Kotlin from Java
Once you compile Kotlin code to bytecode, you can use the .class files and JAR files created from Kotlin source files in Java projects. Alternatively, you may also intermix Kotlin source files, side by side, with Java source files and call Kotlin code from within Java code. We’ve already seen the mechanics to make this work. Let’s now focus on the issues with source code we may run into with such integration efforts.
Kotlin has a number of features that don’t exist in Java. Also, Kotlin is idiomatically different from Java in many ways. Thus, the Kotlin way of doing things that work elegantly and expressively when writing code in Kotlin won’t work when calling Kotlin code from Java.
If the Kotlin code you’re creating ...
Get Programming Kotlin now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.