Practical Kotlin Deep Dive
Unpacks the "how" and "why" behind Kotlin from core language fundamentals and internal mechanisms to API design. Covers Kotlin fundamentals, standard library, coroutines, kotlinx libraries, compiler internals, and Kotlin Multiplatform.
This book goes beyond the API surface and dives into Kotlin under the hood: walks through real implementations of Kotlin functions, demystifies the generated bytecode, and explains how the Kotlin compiler interprets the language.
Loved by engineers from top global tech companies
Everything You Need to Master Kotlin
What Sets This Book Apart
From in-depth explanations to practical code references
๐In-Depth Explanations
Each topic provides detailed explanations that go beyond surface-level knowledge, exploring not just how Kotlin features work but why they were designed that way.
๐กPro Tips for Mastery
The Pro Tips sections dive deeper into advanced topics, uncovering internal structures of Kotlin fundamentals, and offering expert insights for immediate application.
๐References to Source Code
Find references to KEEP proposals, JetBrains YouTrack discussions, and compiler source code, giving direct insight into design decisions.
๐Comprehensive Coverage
From Language Fundamentals to Standard Library, Coroutines, Compiler and Plugins, and Kotlin Multiplatform โ practical knowledge that makes a real difference.
Content Structure
What's Inside This Book
Six comprehensive chapters covering every aspect of Kotlin development
Kotlin Language
Covers Kotlin's foundational building blocks, from null safety and type system design to advanced features like sealed classes, inline functions, and delegation.
Kotlin Standard Library
Deep exploration of Kotlin's rich standard library, including collections, sequences, scope functions, and utilities that make Kotlin code expressive and concise.
Coroutines
Comprehensive exploration of Kotlin's approach to asynchronous programming. From suspending functions and coroutine builders to structured concurrency, Flow, and exception handling.
KotlinX Libraries
Explore official Kotlin libraries developed by JetBrains that extend the language with additional functionality including serialization, date/time, and immutable collections.
Kotlin Compiler & Plugins
Takes you under the hood of how Kotlin code transforms into executable programs. Learn compiler architecture, K2 compiler, FIR, IR, and how to create compiler plugins.
Kotlin Multiplatform
Explore Kotlin's cross-platform capabilities, covering project structure, source set hierarchy, platform interoperability, and Compose Multiplatform for shared UI development.
Testimonials
What Developers Say
Hear from industry experts and GDEs who have read the book
โSince Kotlin was designated as the official language for Android development, it has been loved by many developers and has grown beyond the Android platform. This book is written precisely for these developers. It dives deep into the core principles and internal mechanisms of Kotlin. If you're a Kotlin developer who truly wants to understand the language and elevate your skills to the next level, I highly recommend reading this book.โ
โPractical Kotlin Deep Dive is an exceptionally comprehensive guide that goes beyond syntax to explore the internal mechanisms and design philosophy of the Kotlin language. What makes it stand out is Jaewoong's unique perspective as both a GDE and a prolific open-source contributor โ he brings battle-tested, practical advice that bridges theory and real-world application.โ
โExceptionally well written, breaking down complex concepts into clear and understandable explanations. In an era where AI tools are readily available, this book stands out and is worth every cent. It offers a depth and clarity that you won't easily find elsewhere.โ
โKotlin has evolved from a simple programming language into the core of multiplatform development. This book goes far beyond basic usage to dive deep into the design philosophy and internal mechanisms of Kotlin. It is a must-read for any engineer who wants to truly grasp the core of Kotlin.โ
Reviews
Community Feedback
See what the Kotlin community is saying about the book
Preview
Book Preview
Take a look at the content before you buy
Preview the BookLike what you see? You can read more here:
Global Reach
Available in Multiple Languages
Translated editions for the global Kotlin developer community
Sponsors
Proudly Supported By
Special thanks to our sponsors who support this project
Kotlin Weekly
A weekly newsletter with the best Kotlin articles, libraries, videos, and news delivered directly to your inbox every week.
CodeRabbit is an AI-powered code review platform that integrates directly into pull-request workflows and IDEs, examining code changes and suggesting improvements.
๐ Want to Join?
Interested in sponsoring this book and reaching thousands of Kotlin developers?
[email protected]Now Available in Print
Hardcover & Paperback Edition
Premium quality print with a beautiful dust jacket design
Get on AmazonPractical Kotlin Deep Dive
Master Kotlin with Kotlin Deep Dive Course
An online course unpacking the fundamentals and internal mechanisms of Kotlin programming with coding exercises and quizzes to reinforce concepts.
Table of Contents
70 Deep-Dive Topics
Six comprehensive chapters covering every aspect of Kotlin development
- 1Chapter Overview
- 2The Type System
- 3Null Safety in Kotlin
- 4The Core Principle: A Tale of Two Types
- 5Safely Working with Nullable Types
- 6Interoperability with Java and Platform Types
- 7The Any, Unit, and Nothing Types
- 8Structural and Referential Equality
- 9๐ก Pro Tips for Mastery: How does structural equality (==) work internally?
- 10Properties and Visibility
- 11Variables: var vs val
- 12๐ก Pro Tips for Mastery: Why is the val variable and property read-only and not immutable?
- 13Visibility Modifiers
- 14๐ก Pro Tips for Mastery: How internal visibility modifier is compiled to Java Bytecode?
- 15The init Block
- 16๐ก Pro Tips for Mastery: What are the downsides of init block?
- 17๐ก Pro Tips for Mastery: How init block is compiled to Java Bytecode?
- 18Backing Fields and Backing Properties
- 19Data and Sealed Classes
- 20Data Classes
- 21๐ก Pro Tips for Mastery: Data class inheritance
- 22๐ก Pro Tips for Mastery: The visibility of the copy function of data classes
- 23๐ก Pro Tips for Mastery: Unveiling a data class in Java Bytecode
- 24Sealed Classes
- 25๐ก Pro Tips for Mastery: Sealed class inheritance
- 26๐ก Pro Tips for Mastery: What are the differences between sealed classes and sealed interfaces?
- 27Enum and Value Classes
- 28Enum Classes
- 29๐ก Pro Tips for Mastery: Generic values() and valueOf() for enums
- 30๐ก Pro Tips for Mastery: Decommission Enum.values() and replace it with Enum.entries
- 31๐ก Pro Tips for Mastery: What are the differences between a sealed class and an enum class?
- 32Value Classes
- 33๐ก Pro Tips for Mastery: What are the differences between value classes and inline classes?
- 34๐ก Pro Tips for Mastery: How value class is compiled to Java Bytecode
- 35๐ก Pro Tips for Mastery: @JvmExposeBoxed - Bringing Kotlin's value classes for Java
- 36Objects and Companions
- 37Inner and Nested Classes
- 38Object Declarations
- 39๐ก Pro Tips for Mastery: Object declarations vs. expressions
- 40๐ก Pro Tips for Mastery: What is a data object?
- 41๐ก Pro Tips for Mastery: How Kotlin's object is compiled to Java Bytecode
- 42Companion Objects
- 43Delegation Patterns
- 44Delegated Properties
- 45๐ก Pro Tips for Mastery: Internal mechanisms of Lazy
- 46๐ก Pro Tips for Mastery: How lazy() delegate property is compiled to Java Bytecode?
- 47Lazy Initialization vs lateinit
- 48๐ก Pro Tips for Mastery: How can you check if a lateinit property has been initialized?
- 49๐ก Pro Tips for Mastery: How lateinit is compiled to Java Bytecode
- 50Functions and Lambdas
- 51Higher-Order Functions
- 52๐ก Pro Tips for Mastery: How are higher-order functions compiled into Java bytecode?
- 53Lambda Expressions
- 54Inline and Reified
- 55๐ก Pro Tips for Mastery: What is an inline property?
- 56๐ก Pro Tips for Mastery: How do functions like repeat(), map(), and filter() accept suspending functions?
- 57The reified Keyword
- 58๐ก Pro Tips for Mastery: How inline and reified functions are compiled to Java Bytecode
- 59Functional (SAM) Interfaces
- 60๐ก Pro Tips for Mastery: A philosophy of SAM conversion
- 61Extensions and DSL
- 62Extension Functions
- 63๐ก Pro Tips for Mastery: How are Kotlin extension functions compiled into Java bytecode?
- 64๐ก Pro Tips for Mastery: JvmSynthetic annotation
- 65Domain-Specific Languages (DSL)
- 1Chapter Overview
- 2Collections and Transformations
- 3Collection Types
- 4Read-Only Collection Types
- 5Mutable Collection Types
- 6๐ก Pro Tips for Mastery: What are the differences between listOf() and emptyList()?
- 7Transformation Operators
- 8map and mapIndexed
- 9flatMap and flatten
- 10groupBy and associateBy
- 11zip and unzip
- 12filter, filterNot, and filterIndexed
- 13Iterators and Sequences
- 14Iterators
- 15MutableIterator
- 16Sequences
- 17Collection Retrieval
- 18Retrieving Parts of Collections
- 19Ordering and Sorting
- 20Scope Functions
- 21let, run, with, apply, also
- 22Choosing the Right Scope Function
- 1Chapter Overview
- 2Coroutines Basics
- 3How Coroutines Work
- 4Launching Coroutines
- 5Suspending Functions
- 6๐ก Pro Tips for Mastery: Coroutines Terminology
- 7Continuation
- 8How Kotlin Compiler Transforms Suspend Functions
- 9Coroutines vs Threads
- 10๐ก Pro Tips for Mastery: What are the differences between multi-threading and multi-processing?
- 11๐ก Pro Tips for Mastery: Coroutine Execution and Mutable State Management
- 12Coroutine Builders
- 13launch, async, runBlocking, produce, actor
- 14๐ก Pro Tips for Mastery: What are the differences between launch and async?
- 15๐ก Pro Tips for Mastery: Why should you use runBlocking with caution?
- 16๐ก Pro Tips for Mastery: Internal mechanisms of the AbstractCoroutine
- 17Coroutine Context and Job
- 18Coroutine Context
- 19๐ก Pro Tips for Mastery: CoroutineContext interface
- 20Job
- 21๐ก Pro Tips for Mastery: What's a SupervisorJob?
- 22Coroutine Scope
- 23GlobalScope, MainScope, viewModelScope, lifecycleScope
- 24๐ก Pro Tips for Mastery: Why should you use GlobalScope carefully?
- 25๐ก Pro Tips for Mastery: What is the coroutineScope() function?
- 26๐ก Pro Tips for Mastery: What is the supervisorScope() function?
- 27Dispatchers and Channels
- 28CoroutineDispatcher
- 29๐ก Pro Tips for Mastery: Differences between CPU-intensive tasks and I/O tasks
- 30๐ก Pro Tips for Mastery: Internals of Dispatchers
- 31Channels
- 32๐ก Pro Tips for Mastery: Internals Mechanisms of Channel
- 33Coroutine Control and Exception Handling
- 34join() and yield() functions
- 35Exception handling in coroutines
- 36๐ก Pro Tips for Mastery: The special nature of CancellationException
- 37๐ก Pro Tips for Mastery: Handling exception propagation when using async
- 38Flow Basics
- 39Cold flow vs Hot flow
- 40๐ก Pro Tips for Mastery: Internal mechanisms of Flow and AbstractFlow
- 41StateFlow and SharedFlow
- 42๐ก Pro Tips for Mastery: Internal Mechanisms of StateFlow
- 43๐ก Pro Tips for Mastery: Internal Mechanisms of SharedFlow
- 44Flow Operators
- 45flowOn, buffer operators
- 46๐ก Pro Tips for Mastery: Internal Mechanisms of flowOn
- 47๐ก Pro Tips for Mastery: Internal Mechanisms of Flow.buffer()
- 48FusibleFlow and ChannelFlow optimization
- 49Flow Transformations
- 50launchIn vs Scope.launch
- 51flatMapLatest, flatMapMerge, flatMapConcat
- 52callbackFlow and channelFlow
- 1Chapter Overview
- 2KotlinX Essentials
- 3Kotlinx Serialization
- 4How Serialization Works
- 5Customizing Serialization
- 6JSON Configuration
- 7Polymorphic Serialization
- 8Multiplatform Support
- 9Kotlinx Datetime
- 10Working with Time Zones
- 11Date Arithmetic
- 12Duration and Period
- 13Parsing and Formatting
- 14Kotlinx Collections Immutable
- 15Truly Immutable Collections
- 16Persistent Collections
- 17Builders for Efficient Bulk Operations
- 18Other Notable KotlinX Libraries
- 19kotlinx-atomicfu
- 20kotlinx-io
- 21kotlinx-benchmark
- 22Dokka
- 23kotlinx-rpc
- 24Kover
- 1Chapter Overview
- 2Annotation Processing
- 3Annotation Processors, KAPT, and KSP
- 4Performance Comparison
- 5Migration from KAPT to KSP
- 6Kotlin Compiler Architecture
- 7Structure of the Kotlin Compiler
- 8High-Level Architecture
- 9Frontend and Backend
- 10The Role of IR
- 11The K2 Compiler
- 12Why K2?
- 13Key Improvements
- 14FIR Compilation Phases
- 15K2 for Plugin Authors
- 16Migration to K2
- 17Frontend Intermediate Representation (FIR)
- 18FIR in the K2 Compiler
- 19FIR Element Hierarchy
- 20FIR Resolution Phases
- 21Working with FIR: Symbols and Providers
- 22ConeKotlinType: The Type System
- 23Intermediate Representation and Backends
- 24IR and the Kotlin Backend
- 25IR Tree Structure
- 26Key IR Element Types
- 27IR Lowering: High-Level to Low-Level
- 28Platform-Specific Backends
- 29Writing Kotlin Compiler Plugins
- 30Plugin Architecture Overview
- 31Step-by-step: Define Annotation, Command Line Processor, Component Registrar
- 32Implement K2 FIR Extension
- 33Implement IR Generation Extension
- 34Create Gradle Plugin
- 35Real-World Compiler Plugin Examples
- 36Kotlinx Serialization Plugin
- 37Jetpack Compose Plugin
- 38Parcelize Plugin
- 39All-Open and No-Arg Plugins
- 1Chapter Overview
- 2KMP Fundamentals
- 3Kotlin Multiplatform Overview
- 4Key Features and Advantages
- 5Kotlin Multiplatform Architecture
- 6Expect and Actual Declarations
- 7What Can Be Expected/Actual
- 8Default Implementations
- 9Compiler Guarantees
- 10Concurrency and Asynchronous Programming
- 11Kotlin Coroutines: The Primary Solution
- 12Platform-Specific Dispatchers
- 13Structured Concurrency in Multiplatform
- 14HTTP Network Communication
- 15Ktor Client
- 16Platform-Specific Engines
- 17Ktorfit
- 18Compose Multiplatform
- 19How Compose Multiplatform Works
- 20Writing Shared UI
- 21Supported Platforms and Stability
- 22Resources and Platform Integration
- 23Navigation and Architecture
- 24Source Set Structure
- 25Source Sets in Kotlin Multiplatform
- 26Default Source Set Hierarchy
- 27Intermediate Source Sets
- 28Dependencies Per Source Set
- 29Kotlin/Native
- 30Memory Management
- 31Interoperability with Objective-C and Swift
- 32Coroutines and Swift Async/Await
- 33Performance Considerations
- 34Testing Strategies
- 35Common Test Structure
- 36Testing Coroutines
- 37Platform-Specific Tests
- 38Integration Testing
- 39Dependency Injection Strategies
- 40Metro: Compile-Time DI
- 41Koin: KSP-Based Compile-Time DI
- 42Kodein-DI: Flexible Runtime Container
- 43Manual Dependency Injection
Journey
Timeline & Milestones
Key moments from the book's journey

