Interoperability lets Kotlin fit into existing JVM systems instead of requiring an isolated rewrite. Kotlin code can extend, call, annotate, and replace Java components while preserving practical reliability and maintainability. section 1.3.1 section 1.4.4
Listing 1.2 Writing Spring Boot applications in Kotlin
@SpringBootApplication #1
class DemoApplication
fun main(args: Array<String>) {
runApplication<DemoApplication>(*args)
}
@RestController
class GreetingResource {
@GetMapping
fun index(): List<Greeting> = listOf( #2
Greeting(1, "Hello!"),
Greeting(2, "Bonjour!"),
Greeting(3, "Guten Tag!"),
)
}
data class Greeting(val id: Int, val text: String) #2
A compact Spring Boot application shows Kotlin working with established framework annotations, defining an HTTP JSON endpoint with a data class and minimal code. section 1.3.1
Kotlin supports interoperability at several practical boundaries:
- Call Java methods, extend Java classes, implement Java interfaces, and apply Java annotations to Kotlin declarations. section 1.4.4
- Expose Kotlin classes and methods to Java as regular Java classes and methods, allowing Java and Kotlin to coexist throughout a project. section 1.4.4
- Use Java standard-library collections from Kotlin without wrapping or converting objects; Kotlin adds convenient functions while retaining the underlying classes. section 1.4.4
- Compile mixed Java and Kotlin source files, navigate across languages, debug through both, and keep cross-language refactorings synchronized. section 1.4.4
Incremental migration
A Java project can convert one class at a time with the Java-to-Kotlin converter while the remaining code continues to compile and work without modification. The converted class can retain its existing role, and Kotlin can continue using the project’s Java libraries. section 1.4.4




