Book Description

Kotlin has raised the bar for programming languages on the Java Virtual Machine with its compatibility, readability, efficiency, and tool support. But adopting a new language can be daunting, especially when you're working with business-critical Java code that must meet changing requirements.

This book takes a novel approach to introducing Kotlin to Java programmers: showing you how to gradually refactor Java code to idiomatic Kotlin while continuing to evolve its functionality. But converting Java to Kotlin is just the starting point. Kotlin has many features beyond Java.

Using worked examples, authors Duncan McGregor and Nat Pryce guide you through honing the converted code to make it simpler, more efficient, more expressive, and easier to change. You'll learn how to take advantage of functional constructs to improve program structure, reliability, and error handling.

Once you finish this book, you'll be confident writing Kotlin from scratch, converting your existing Java when appropriate, and managing a mixed Java-Kotlin codebase as it evolves over time.

Table of Contents

  1. Preface
    1. Conventions Used in This Book
    2. Using Code Examples
    3. O’Reilly Online Learning
    4. How to Contact Us
    5. Acknowledgments
  2. 1. Introduction
    1. The Grain of a Programming Language
    2. An Opinionated History of Java Programming Style
      1. Primeval Style
      2. Bean Style
      3. Enterprise Style
      4. Modern Style
      5. The Future
    3. The Grain of Kotlin
    4. Adapting to Kotlin’s Grain
    5. Refactoring to Kotlin
      1. We Minimise Text Edits
      2. We Assume Good Test Coverage
      3. We Commit For Git Bisect
    6. What Are We Working On?
    7. How This Book is Organised
    8. Complexity
    9. Code Conventions
    10. Directions in Code
  3. 2. Java To Kotlin Projects
    1. Migrating a Java Build to Kotlin
    2. Conclusions
  4. 3. Beans to Values
    1. What is a Value?
    2. Why Should We Prefer Values?
    3. Migrating Beans to Values
    4. Conclusions