Preface....7
Testimonial....8
About This Book....9
Who This Book Is For....9
What This Book Covers....9
How to Use This Book....10
Staying Current....10
Issue Reports....10
Sponsors....11
CodeRabbit....11
Chapter 0. Kotlin Language....12
Q) 0. Explain the null safety in Kotlin....13
Q) 1. What are the primary roles of the Any, Unit, and Nothing types?....16
Q) 2. What is a data class, and how does it differ from a regular class?....19
Q) 3. What is a sealed class and explain the use cases....23
Q) 4. What is an inner class and what are the differences from a nested class?....25
Q) 5. When do you use an enum class?....29
Q) 6. What is a value class?....33
Q) 7. What is an object and what are the differences from a regular class?....38
Q) 8. What is a companion object?....44
Q) 9. What are the differences between var and val?....46
Q) 10. What are the differences between backing fields and backing properties?....48
Q) 11. What’s a delegated property?....49
Q) 12. What are the differences between the lazy delegate and lateinit?....54
Q) 13. What visibility modifiers exist?....58
Q) 14. When is the init block invoked, and what are its key characteristics?....60
Q) 15. What is the higher-order function, and what advantages can you take?....65
Q) 16. What are the benefits and limitations of an inline keyword?....68
Q) 17. What’s a reified keyword, and what are the benefits of using it?....73
Q) 18. How do you use a lambda expression?....76
Q) 19. What are functional (SAM) interfaces?....77
Q) 20. What’s extension, and what are its pros and cons?....79
Q) 21. What are structural equality and referential equality, and how do they differ?....85
Q) 22. What happens when you run null + null operation?....87
Q) 23. What is DSL and how can it be utilized?....87
Chapter 1. Kotlin Standard Library....91
Q) 24. What collection types exist in Kotlin?....92
Q) 25. What types of transformation operators are available for collections?....95
Q) 26. Explain the mechanisms of Iterators....100
Q) 27. What is a Sequence and its mechanism?....102
Q) 28. What types of extension functions are available for retrieving parts of a collection?....105
Q) 29. How do you define the ordering of objects?....112
Q) 30. What are the scope functions?....120
Chapter 2. Coroutines....124
Q) 31. What are Coroutines?....125
Q) 32. What is a Continuation, and how is it related to a suspend function internally?....127
Q) 33. What are the differences between coroutines and threads?....130
Q) 34. What are coroutine builders?....134
Q) 35. What is a coroutine context?....148
Q) 36. What is the role of a Job?....152
Q) 37. What is the purpose of a coroutine scope?....158
Q) 38. What kind of coroutine dispatchers exist, and what’s their purpose?....168
Q) 39. What are channels and how do they work?....173
Q) 40. What are the join() and yield() functions?....178
Q) 41. How do you handle exceptions in coroutines?....181
Q) 42. What are the differences between cold flow and hot flow?....187
Q) 43. Explain the differences between StateFlow and SharedFlow....191
Q) 44. What does the Flow.flowOn() operator do?....197
Q) 45. How Flow.buffer() operator works?....200
Q) 46. How Kotlin’s internal mechanisms optimize Flow with FusibleFlow and ChannelFlow....204
Q) 47. What are the differences between launchIn(Scope) and Scope.launch()?....206
Q) 48. What are Flow transformation operators: flatMapLatest, flatMapMerge, flatMapConcat?....207
Q) 49. What are callbackFlow and channelFlow, and their internal mechanisms?....211
Chapter 3. KotlinX Libraries....217
Q) 50. What is kotlinx-serialization and how does it work?....218
Q) 51. What is kotlinx-datetime and why use it over Java time APIs?....220
Q) 52. What is kotlinx-collections-immutable and when should you use it?....223
Q) 53. What other notable KotlinX libraries exist?....225
Chapter 4. Kotlin Compiler and Plugins....229
Q) 54. What are annotation processors, KAPT, and KSP?....230
Q) 55. What is the structure of the Kotlin Compiler?....232
Q) 56. What is the K2 compiler?....235
Q) 57. What is FIR (Frontend Intermediate Representation)?....238
Q) 58. What is IR and how does the Kotlin backend work?....242
Q) 59. How do you write a Kotlin Compiler Plugin?....247
Q) 60. What are some real-world Kotlin compiler plugin examples and use cases?....255
Chapter 5: Kotlin Multiplatform....259
Q) 61. What is Kotlin Multiplatform?....260
Q) 62. How does Kotlin Multiplatform handle platform-specific APIs and share the common codes?....262
Q) 63. What strategies are available for concurrency or asynchronous programming in Kotlin Multiplatform?....264
Q) 64. What strategies are available for HTTP network communication in Kotlin Multiplatform?....266
Q) 65. What is Compose Multiplatform?....268
Q) 66. How are source sets structured in a Kotlin Multiplatform project?....272
Q) 67. How does Kotlin/Native handle memory management and platform interoperability?....276
Q) 68. What are the testing strategies in Kotlin Multiplatform?....280
Q) 69. What are the dependency injection strategies in Kotlin Multiplatform?....284
Final Words....291
Takes you from “how to use Kotlin” into “how Kotlin really works,” revealing the internal implementations, desmifying bytecodes and compiler behavior, and internals that shape the language. If you want to write smarter, more confident Kotlin across fundamentals, coroutines, and multiplatform, this is the book that shows you why everything is the way it is.
Practical Kotlin Deep Dive unpacks the “how” and “why” behind Kotlin from core language fundamentals and internal mechanisms to the design of its APIs. It spans Kotlin basics, the standard library, coroutines, kotlinx libraries, compiler internals, and Kotlin Multiplatform.
This book goes beyond surface-level APIs by diving into Kotlin’s internals: it walks through real Kotlin function implementations, demystifies generated bytecode, and explains how the Kotlin compiler interprets the language. It also draws directly from KEEP proposals, JetBrains YouTrack discussions, and compiler source code to connect concepts to their origins and design rationale. The result is an approach that helps you reason about Kotlin instead of simply memorizing APIs.
This progression ensures that you understand not only how to use Kotlin effectively, but also why the language was designed the way it is, giving you insights that translate directly into better code.
For continuous growth, the book includes curated references and additional resources so you can keep exploring beyond its pages. Complex or less common terms are explained with accessible footnotes, making advanced material approachable for newcomers while offering fresh insights to seasoned developers.
The "Pro Tips for Mastery" sections go beneath the surface, covering internal structures of Kotlin functions, algorithms, how the Kotlin compiler behaves, and implementation details that matter in real-world projects. Senior engineers will find thought-provoking details to sharpen their expertise, while mid-level developers gain insights for leveling up their Kotlin knowledge and building a stronger analytical mindset.
Whether you're optimizing performance-critical code, handling complex coroutine tasks, or exploring multiplatform development, this book challenges you to go beyond tutorials. Learn to reason about language design, understand internal mechanisms, and approach Kotlin development with clarity, curiosity, and confidence. You can read previews of Practical Kotlin Deep Dive.