liveBook · Manning

Interoperability

As explained in Kotlin in Action, 2E

The ability of software components, languages, or systems to work together and exchange data or invoke one another across their boundaries.

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

How Kotlin in Action, 2E covers it

How deep it goes
Explains supported Java and tooling interactions with examples, but defers detailed collection mechanisms and deeper interoperability mechanics.
Examples
Uses Spring Boot JSON services, Java-to-Kotlin conversion, Java collections, and cross-language IDE navigation and refactoring.
What it assumes
Assumes an existing JVM or Java ecosystem context while introducing Kotlin’s role in that environment.
What you can do after
Apply it via Kotlin to extend Java classes, consume Java libraries, migrate classes incrementally, and maintain mixed-language projects.
How it connects
Connects interoperability with Java, JVM applications, collections, annotations, nullability, Spring, and mixed-language development tools.

Also explained in

Compare how 5 books explain interoperability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kotlin in Action, 2E. The section links point to the parts of the book it draws on.