Book Image

Mastering Kotlin

By : Nate Ebel
Book Image

Mastering Kotlin

By: Nate Ebel

Overview of this book

Using Kotlin without taking advantage of its power and interoperability is like owning a sports car and never taking it out of the garage. While documentation and introductory resources can help you learn the basics of Kotlin, the fact that it’s a new language means that there are limited learning resources and code bases available in comparison to Java and other established languages. This Kotlin book will show you how to leverage software designs and concepts that have made Java the most dominant enterprise programming language. You’ll understand how Kotlin is a modern approach to object-oriented programming (OOP). This book will take you through the vast array of features that Kotlin provides over other languages. These features include seamless interoperability with Java, efficient syntax, built-in functional programming constructs, and support for creating your own DSL. Finally, you will gain an understanding of implementing practical design patterns and best practices to help you master the Kotlin language. By the end of the book, you'll have obtained an advanced understanding of Kotlin in order to be able to build production-grade applications.
Table of Contents (25 chapters)
Free Chapter
1
Section 1: Kotlin – A Modern Solution to Application Development
4
Section 2: Putting the Pieces Together – Modeling Data, Managing State, and Application Architecture
8
Section 3: Play Nice – Integrating Kotlin With Existing Code
13
Section 4: Go Beyond – Exploring Advanced and Experimental Language Features
17
Section 5: The Wide World of Kotlin – Using Kotlin across the Entire Development Stack

Fixing the billion-dollar mistake

Many developers quickly learn about the challenges associated with handling null types in a programming language. One of the most common errors for Java developers is NullPointerException, which is caused by trying to access an object that is null. In fact, the frustrations attributed to null are so great, it's even been referred to as the "billion-dollar mistake."

Seeing, and understanding, the problems that null has caused in Java and other languages, Kotlin was designed to eliminate null as much as possible. In Kotlin, types are non-null by default. To work with a nullable type requires the explicit addition of the ? symbol. In this section, we'll look at how to define null and non-null types, and a few of the ways we can handle nullable types within our Kotlin code.

...