What's New

Brace yourselves for a crash course in not crashing โ€“ Chapter 17 is here, and it’s all about catching exceptions! If you’re ready for more, Chapter 18, Introduction to Generics, is currently available in draft form for those who have purchased the Leanpub edition of the book!

๐ŸŒŸ๐Ÿš€ Join my newly-launched email newsletter for exclusive updates and bonus content on my latest articles, videos, and projects! Your support has fueled this adventure for over 6 years, and I can’t wait to connect with you in a new way!

Sign Up Now

Latest Articles and Videos

New!

Variance... without Generics!

Unlock the mental model of variance. No generics required!

Variance... without Generics!
New!

Handling Runtime Exceptions

Catch some new knowledge about exception handling with Chapter 17 of 'Kotlin: An Illustrated Guide.' This chapter demystifies runtime errors, offering readers a blend of technical depth and relatable examples to master exception handling in Kotlin. Through vivid illustrations and clear, approachable explanations, learn how to navigate unexpected issues in your code gracefully. Whether you're a beginner eager to solidify your understanding or an experienced developer looking to refresh your knowledge, this chapter turns the complex topic of exceptions into an enjoyable learning experience.

Handling Runtime Exceptions

Introduction to HexFormat

Let's check out HexFormat and its related functions!

Introduction to HexFormat

Intersection Types in Kotlin

Intersection types are not denotable, but we can still use them!

Intersection Types in Kotlin

try-catch vs runCatching

Let's talk about try-catch, runCatching(), and those poll results!

try-catch vs runCatching

Sealed Types

In Kotlin, we can used sealed interfaces and sealed classes to make the compiler even more helpful! In this chapter, we'll learn how to get exhaustive matching with sealed types.

Sealed Types

Leanpub Frontmatter Podcast: Dave Leeds

Len Epp and I talk about Kotlin, learning how to code, publishing on Leanpub, and lots more!

Leanpub Frontmatter Podcast: Dave Leeds

A Tour Through Konsist with Igor Wojda

I team up with special guest Igor Wojda to demonstrate how the Konsist static code analysis tool can be used to ensure consistency in a Kotlin codebase!

A Tour Through Konsist with Igor Wojda

Data Classes and Destructuring

It's easy to use data classes to give your objects superpowers like value equality, a readable toString() implementation, the ability to easily copy values, and the ability to be destructured. In this chapter, we'll learn what they are, how to declare them, and when to use them!

Data Classes and Destructuring

How to Use Kotlin's Timing API

Kotlin's Timing API is stable as of Kotlin 1.9, and it offers some great ways to both measure and specify time. In this video, we'll take a tour through the main features of this API so that you can start using durations and time marks like a pro!

How to Use Kotlin's Timing API

Wall Clock vs. Monotonic Clock

As a prelude to exploring the newly-stable Timing API in Kotlin 1.9, let's check out the difference between a wall clock and a monotonic clock!

Wall Clock vs. Monotonic Clock

Abstract and Open Classes

In this chapter, we'll see how we can create subtypes from abstract classes and open classes. Impress your friends with big words like inheritance and polymorphism!

Abstract and Open Classes

Introduction to Collection Builders

Use Collection Builders to dynamically build out a collection's contents, without leaving it open to modifications.

Introduction to Collection Builders

Smart Casts with Kotlin Contracts

Use the experimental Contracts feature to create a Smart Cast from your own function.

Smart Casts with Kotlin Contracts

Introduction to Class Delegation

Use Kotlinโ€™s class delegation feature to forward function calls from one object to another - without all the usual boilerplate!

Introduction to Class Delegation

Easy SharedPreferences with Delegated Properties

Learn how Kotlin's delegated properties work by turning Android's SharedPreferences into a delegate.

Easy SharedPreferences with Delegated Properties

5 Fun Ways to Use Extension Functions

Let's put extension functions together with operator function conventions to do some crazy things!

5 Fun Ways to Use Extension Functions

5-Year Celebration: Peek Behind the Scenes!

Get a peek behind the scenes, including my art setup, my writing tooling, and even my cute dog!

5-Year Celebration: Peek Behind the Scenes!

Introduction to Interfaces

In Kotlin, interfaces are one way to give a class more than one type at the same time. In this chapter, learn about interfaces and implementations, plus smart casts, interface inheritance, multiple interfaces, and default implementations.

Introduction to Interfaces

Scopes and Scope Functions

Kotlin's scope functions - with(), run(), let(), also(), and apply() - introduce a new scope where an object can be easily used. Learn about two different kinds of scopes and how they affect visibility. Then, explore all five scope functions, and learn how shadowing affects implicit receivers.

Scopes and Scope Functions

Receivers and Extensions

Use Kotlin extensions to add new functions and properties to existing classes - even to classes that you didn't write! Learn all about explicit receivers, implicit receivers, extension functions, and extension properties in this chapter.

Receivers and Extensions

Collections: Maps

Maps in Kotlin are used to associate keys and values. In this chapter, we'll learn all about them, including mutable and immutable maps, map operations like forEach() and filter(), and how to convert lists into maps with associate() and groupBy().

Collections: Maps

Collections: Lists and Sets

Kotlin collections give you powerful control over groups of objects. In this chapter, we'll look at List and Set collection types, and we'll learn about collection operations - including mapping, filtering, and sorting.

Collections: Lists and Sets

Lambdas and Function References

In Kotlin, you can pass a chunk of code from one function to another. In this chapter, we'll learn how to do that, covering topics like function types, function references, lambdas, higher-order functions, and much more.

Lambdas and Function References

Nulls and Null Safety

In Kotlin, null safety is a first-class concept. In this chapter, we'll learn all about nulls, including how to manage them with tools like smart casts, elvis operators, safe-call operators, and more.

Nulls and Null Safety

Enum Classes in Kotlin

Enumeration classes can improve your code by limiting values to only those that could be correct. In this chapter, we'll learn all about enum classes in Kotlin!

Enum Classes in Kotlin

Examples of Classes in Kotlin

A quick reference that shows how to create classes in Kotlin, with examples that include properties, functions, inheritance, generics, and more.

Examples of Classes in Kotlin

Introduction to Classes and Objects

Classes and objects are everywhere in Kotlin! In this chapter, we'll put variables and functions together to create our very own types, using Kotlin classes.

Introduction to Classes and Objects

Kotlin Conditionals: When and If

Kotlin has two important conditionals: when and if. They can be used either as expressions or as statements. In this chapter, we'll use illustrations and examples to demonstrate how to use them.

Kotlin Conditionals: When and If

Functions

Learn all about Kotlin functions the fun and easy way, with lots of examples and illustrations! Expression bodies, block bodies, named arguments, default arguments, and lots more.

Functions

Variables, Expressions, and Types

So you want to be a Kotlin programmer? You've come to the right place! Your adventure starts here in Chapter 1, where you'll learn all about variables, expressions, and types.

Variables, Expressions, and Types

When to Use Sequences

When should you use Kotlin sequences? And when should you use normal collections? In this article, we'll look at some of the characteristics that can have the biggest impact on performance.

When to Use Sequences

Inside Sequences: Create Your Own Sequence Operations

Learn how to create your very own sequence operation by understanding how Kotlin's sequences work on the inside.

Inside Sequences: Create Your Own Sequence Operations

Kotlin Sequences: An Illustrated Guide

An illustrated introduction to Sequences in Kotlin - easy-to-understand diagrams that demonstrate the difference between regular collection operations and sequence operations.

Kotlin Sequences: An Illustrated Guide

Inline Classes and Autoboxing

Get the best performance out of Kotlin's Inline Classes feature by understanding when they're inlined and when they're autoboxed.

Inline Classes and Autoboxing

An Introduction to Inline Classes

An introduction to Kotlin's inline value classes, which can give you strong types for simple values - without sacrificing performance.

An Introduction to Inline Classes

How to Enable Kotlin 1.3 Inline Classes Today

How to configure your IDE to use Kotlin 1.3 early access so that you can start exploring inline classes and other new features. Includes instructions for Gradle, Maven, IntelliJ IDEA, and Android Studio.

How to Enable Kotlin 1.3 Inline Classes Today

Parameters and Arguments: An Easy Way to Remember the Difference

Parameters and arguments aren't the same thing. Here's an easy way to remember the difference.

Parameters and Arguments: An Easy Way to Remember the Difference

All About Type Aliases in Kotlin

Kotlin's type aliases give you a quick and easy way to create simple, concise, and domain-specific names for types. This guide covers all of the essential concepts, with plenty of examples to help you level up your Kotlin game.

All About Type Aliases in Kotlin

Star-Projections and How They Work

What are star-projections in Kotlin? And why do they change your function parameter and return types? With just two easy-to-understand rules, we can illuminate star-projections and understand exactly why they work like they do.

Star-Projections and How They Work

The Ins and Outs of Generic Variance in Kotlin

The ultimate guide to understanding generics, covariance, contravariance, and type projections in Kotlin. Learn two simple subtyping rules that explain why generic variance works the way that it does.

The Ins and Outs of Generic Variance in Kotlin

An Illustrated Guide to Covariance and Contravariance in Kotlin

Confused about generic subtyping? With just a few simple, foundational concepts, almost everything about variance becomes clear. If you're confused about how subtyping works with generics in Kotlin, start here.

An Illustrated Guide to Covariance and Contravariance in Kotlin