Mixing Kotlin and Java in a project
Using different languages within the same project is quite common; I came across projects where a mix of Java and Scala files formed the code base. Could we do the same with Kotlin? Absolutely. Let's work on the project created earlier, Kotlin with Gradle. You should see the following directory structure in your IntelliJ (the standard template for a Java/Kotlin project):
Project layout
You can place Java code within the java
folder. Add a new package to the java
folder with the same name as the one present in the kotlin
folder: com.programming.kotlin.chapter01
. Create a New | Java class named CarManufacturer.java ...
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.