Java Interop: Mix Kotlin into Existing Projects
Harry
· 23 Sep 2026
· 2 views
Log in to track your progress and mark lessons complete.
Sponsored
Calling Java from Kotlin
Call Java directly; getters become properties: user.name calls getName(). Java lists map to Kotlin (Mutable)List.
Calling Kotlin from Java
- @JvmStatic - expose companion methods as real Java statics.
- @JvmOverloads - generate Java overloads for default args.
- @JvmField - expose a property as a public field.
- Top-level functions land in a
FileNameKtclass; rename with@file:JvmName.
Nullability Annotations That Matter
// Java side - helps Kotlin trust your APIs:
public @NotNull String slug(@NotNull String title)Annotate Java boundaries and Kotlin treats them as non-null - fewer surprises, fewer !!.
Checked Exceptions and SAM
- Kotlin has no checked exceptions - Java ones become runtime callables.
- Java functional interfaces convert with lambdas:
executor.submit { work() }. - Use
fun interfacein Kotlin for the same SAM trick.
Migration Strategy That Works
- New files in Kotlin, old files untouched.
- Convert high-value POJOs to data classes first.
- Convert utils to extension functions.
- Convert one module per sprint with tests green throughout.
Key Points
- Interop is bidirectional and reliable.
- Annotations at boundaries buy null safety.
- Migrate module by module, never big-bang.