Chapter 3. Java to Kotlin Classes

The class is the basic unit of code organization in Java. How do we convert our Java classes to Kotlin, and what differences will we see when we have?

In this book, we’ll work together on the code in Travelator, our fictional trip-planning web app. Imagine that we have a feature to implement, but we want to take the opportunity to make our code a little better before we do. You’re pairing with one of Nat or Duncan (choose your favorite, just don’t let Nat know). The pair is the we in our refactoring discussions; not just your author, but also you as part of the team working on Travelator. Welcome aboard!

A Simple Value Type

Let’s jump into the deep end of the codebase and convert some of our existing Java to Kotlin, starting with EmailAddress. This is a value type that holds the two parts of, you guessed it, an email address: ...

Get Java to Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.