Throughout this book, you have learned the fundamentals of the Kotlin programming language, and we hope you are inspired to use Kotlin to improve existing Java projects you may have. Where do you start?
You have seen before that Kotlin compiles down to Java bytecode. This means that Kotlin is interoperable with Java – that is, it functions alongside and works with Java code.
This is likely the most important feature of the Kotlin programming language. Full interoperability with Java means that Kotlin files and Java files can exist in the same project, side by side. You can invoke Java methods from Kotlin and Kotlin functions from Java. This means you can use existing Java libraries from Kotlin, including the Android framework.
Full interoperability with Java also means that you can slowly transition your codebase from Java to Kotlin. Maybe you do not have the opportunity to rebuild your project entirely in Kotlin – consider moving new feature development to Kotlin. Perhaps you would like to convert the Java files in your application that will see the most benefit from a move to Kotlin – consider converting your model objects or your unit tests.
This chapter will show you how Java and Kotlin files interoperate and discuss the things you should consider when writing code that will interoperate.