Chapter 12. Functions to Operators

If we have a large Java codebase, our Java and Kotlin will have to coexist for some time. What can we do to support the conventions of both languages as we gradually translate the system to Kotlin?

So far, we have shown the translation of code from Java to Kotlin happening all in one go. We have used automatic refactorings to perform the translation safely, but by the end, all the affected code has been converted to idiomatic Kotlin.

In large codebases, this is not always possible. We must continue to evolve features in Java while we are introducing Kotlin. Where there is a boundary between the two, we want to use conventional Java on one side and conventional Kotlin on the other. This is especially true when we convert foundational classes that support a lot of our system’s functionality.

A Foundational Class: Money

Every system contains some foundational classes that many parts of the codebase use. An example in Travelator is the Money class, which we first saw in Chapter 3. Travelers need to budget for their trips. They want to compare costs of different travel options, see those costs converted to the their preferred currency, book things, pay for things, and so on. The Money class is so widely used that we cannot convert it and all the code that depends on it to idiomatic Kotlin in one fell swoop. We have to continue working on features that use Money in both Java and Kotlin while the conversion is ongoing.

This leaves us between Scylla ...

Get Java to Kotlin now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.