in general how often kotlin and java used in the s...
# getting-started
j
in general how often kotlin and java used in the same project? is it recommended?
c
It is very often used, and yes it is recommended. The only difficulties you may have will be with coroutines (because they don't exist in Java), everything else interoperates really easily.
r
You can easily mix java and kotlin. There are cases when it's necessary. I personally often use Kotlin with SOAP web services, when some artifacts can only be generated as java sources.
k
It's a bit easier if you're using Gradle than Maven.
đź‘Ť 1
s
I mostly see it while I - over time - refactor a java project to kotlin. Or while I use a java lib in kotlin code. Works like a charm. There are some useful annotations to know about to finetune the jvm representation of your kotlin code to better mix with java code: https://www.baeldung.com/kotlin/jvm-annotations
âž• 1
j
thank you guys understood!
s
Indeed, I mixed it too while porting/migrating Java libs to Kotlin in many steps. It’s a seamless experience. It helped a lot while converting Apache Commons Imaging to Ashampoo Kim. I first copied all the original Java code into a KMP template and added unit tests written in Kotlin. The original project didn’t have good ones and I needed to make sure not to break anything. And then I converted class by class while executing the tests in between. Sometimes the interop is a bit strange with data classes and you need to do stuff with the JVM annotations to make it work, but in general everything can be made to work and is stable. Personally I would have no fear to gradually convert any Java project to Kotlin in production. Just start writing new code in Kotlin today and convert old code when there is time. 🙂
âž• 1