Java Interop in Kotlin

From the Kotlin cheat sheet · Interoperability · verified Jul 2026

Java Interop

Calling Java from Kotlin and vice versa

kotlin
// Calling Java from Kotlin
val list = ArrayList<String>()  // Java class
list.add("item")
list.remove("item")

// Platform types
val item = list[0]  // Platform type String!
// Can be treated as nullable or non-null
val nullable: String? = item
val nonNull: String = item  // May throw NPE

// Java getters/setters as properties
// Java: class Person { getName(); setName(String) }
val person = Person()
person.name = "Alice"  // Calls setName
val name = person.name  // Calls getName

// Static members
val result = Math.max(5, 10)  // Java static method
val pi = Math.PI  // Java static field

// SAM conversion
val runnable = Runnable {
    println("Running")
}

button.setOnClickListener { view ->
    // SAM conversion for Java interfaces
}
💡 Platform types (!) can be null, handle carefully
⚡ @JvmStatic makes companion members static in Java
📌 SAM conversion works for Java functional interfaces
🟢 Use @JvmOverloads for Java-friendly default parameters
Back to the full Kotlin cheat sheet