
There is a fair amount of overlap in keywords between Kotlin and Java, such as class and return. However, it may raise some challenges when using reflection or similar techniques that inspect class details at runtime. Usually, we do not think about this much.

The Kotlin documentation has the full roster of mapped types. Certain core Java classes, like Object and String, get turned into Kotlin equivalents ( Any for Object, and Kotlin’s own String class instead of ).“Boxed” Java primitives, like Integer, are turned into instances of the corresponding nullable Kotlin class, like Integer?.Java primitives, like int, are turned into instances of Kotlin classes, like Int.There is a long list of Java types that get “mapped” to Kotlin native types. If you have a Java class named, and you create an instance of it in Kotlin, you get a object. Java methods that “return” void, when referenced in Kotlin, really return Unit. (the latter compiles but is no longer a function type) Typealias SomeKotlinInterface = ( String ) The so-called “JavaBeans” method structure in Java involves paired methods, prefixed with get and set(), with a common base and using a common type: If you spend time on a Kotlin/JVM project in an IDE that offers Kotlin auto-complete (e.g., Android Studio, IntelliJ IDEA), you will rapidly discover that Kotlin allows you to invoke certain Java methods as if they were Kotlin properties or other simpler forms of Kotlin syntax. In this section, we will explore some things that you will need to consider as you have your Kotlin code call out to Java classes and methods. This is one of the reasons why Google was comfortable in endorsing Kotlin - if having Kotlin code call into the Android SDK was going to be some huge problem, Google might have been more cautious. There are a variety of occasions where you will need to think about interoperability, but for the most part, “it just works”.


On the whole, things tend to work fairly smoothly.

While they may get some Kotlin wrappers, many developers will wind up working with them directly. In particular, many major frameworks are implemented in Java, such as the Android SDK and Spring. While Kotlin libraries are growing in number, they pale in comparison to the vast array of Java libraries. Particularly for new projects, most likely you will be focused on Kotlin code calling into Java code.
