Level up your Kotlin the fun way! Solve mysteries, dodge traps, and banish bugs. Sharpen your critical thinking to ace interviews and ship rock-solid code. Can you outsmart the Kotlin compiler? Detect, deduce, and diagnose your way to clearer code and expert insights. Escape type-system traps and navigate logic labyrinths. Challenge your skills and quiz your friends with fun Kotlin facts, and power up your code with nuanced mastery of data types, functions, and programming techniques. Stay sharp, know your threats, and reason critically to fix bugs before they happen. Laugh at unexpected outcomes and puzzle over awkward edge cases, then ace your next interview with memorable payoffs that simplify key concepts in Kotlin and computer science. Put the fun in functions and laugh while you learn with programming puzzles that challenge your intuition and sharpen your skills. Guess each simple program's output--if you can--then run the code or turn the page to find out what's not as it seems. Deepen your understanding of key data types and put computer science in context as you make deductions and discoveries that will upgrade your apps. Play around and break things to uncover the deliberate design decisions behind Kotlin's unexpected quirks and reveal the why, not just the what. Take on the type system and smuggle null values past the compiler's defenses. Overload operators and turn math on its head as you crack floating-point conundrums. Think like a computer and predict your program's path when you test the limits of control-flow keywords. Harness the power of iteration and immutability to tame devious data and curate collections with confidence. Unravel ambiguous lambda functions and streamline inscrutable syntax. Dodge destructuring dilemmas, spot sneaky shadowing, and know the dynamic difference between members and extensions. Prepare for interviews, tests, competitions, real-world projects, and more with powered-up problem-solving proficiency, improved coding confid
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
Tip the Site
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat Pay
Alipay
Open WeChat or Alipay and scan. No login required.
AI guide
【One-Line Pitch】
A puzzle-driven tour of Kotlin's most counterintuitive corners, where each short program asks you to predict the output before revealing why the compiler and runtime behave the way they do. Best for developers who already write Kotlin and want to sharpen their mental model, prepare for interviews, or finally understand the "weird" cases.
【Book Arc】
- **Opening (~0%–10%)**: Front matter and the table of contents lay out the book's method—23 self-contained puzzles, each with a code snippet, a "guess the output" prompt, a discussion, and further reading. This stage sets expectations and explains the puzzle format rather than teaching concepts.
- **Early (~10%–30%)**: The first puzzles focus on operators and nullability—how `null + null` resolves through operator overloading, how Elvis precedence causes silent bugs, and how floating-point representation makes `0.1 + 0.2` inexact. The problem being solved is learning to read expressions the way the compiler does.
- **Middle (~30%–55%)**: Attention shifts to types and initialization—floating-point edge cases like `NaN` equality and precision loss, then object initialization order and circular dependencies between objects. This stage builds a model of what happens before and during object construction.
- **Late (~55%–85%)**: The excerpts thin out here, but the table of contents signals coverage of control flow, iteration and immutability, collections, lambdas and syntax ambiguity, destructuring, shadowing, and the member-versus-extension distinction. The excerpts do not cover these puzzles in detail.
- **Ending (~85%–100%)**: The final puzzles (through Puzzle 23, "Bringing Up the Rear") close the collection, with the book's structure implying a cumulative payoff rather than a new topic. The excerpts do not cover the closing discussions.
【Book Arc note】
The progression is thematic rather than a curriculum: operators → numeric representation → initialization → control flow → functions and collections. Each puzzle is independent, so the "arc" is really a widening lens on the language.
【Key Takeaways】
- **Operators are overloaded functions, and `null + null` compiles** (Early): Kotlin resolves `+` by searching for a `plus` function that accepts nullable inputs; string concatenation is the only candidate, so nulls become the literal text "null". The lesson is that operator resolution follows type rules, not intuition.
- **Operator precedence silently rewrites your intent** (Early): In `bonus ?: 0 + salary`, addition binds tighter than Elvis, so the fallback never applies as written. The fix is parentheses, not memorization—clarify any expression with more than one operator.
- **Floating-point values are approximations, not exact numbers** (Early): Binary representation makes `0.1 + 0.2` slightly off, and comparisons should use tolerances (e.g., `assertEquals` with an absolute tolerance) or `BigDecimal` when precision matters.
- **Precision limits can make arithmetic non-monotonic** (Middle): Adding `1f` to a large `Long` can produce a *smaller* result after conversion, because the float cannot represent every integer. Fixed-width floating point trades exactness for space and speed.
- **`NaN` breaks the law of self-equality—but only when typed as a float** (Middle): `Double.NaN == Double.NaN` is false per IEEE 754, yet the same value compared as `Any` returns true. The comparison method depends on the static type, a trap worth knowing in numeric code.
- **Object initialization can leak placeholder values through cycles** (Middle): Lazily initialized objects allocate blank slots first, then run initializers; a circular reference reads the blank `null` before it is filled, and that null can be stored into a non-nullable property. Initialization order is a real source of bugs, not a formality.
- **The book's core method is prediction before execution** (Early): Every puzzle asks you to commit to an answer before running the code. This deliberate guessing is what converts passive reading into a corrected mental model—the value is in being wrong and understanding why.
- **Quirks reflect deliberate design decisions** (Early): The discussions consistently trace behavior back to language design, the standard library, or hardware specifications (like IEEE 754), teaching "why" rather than trivia.
【Reading Tips】
- **Guess before you turn the page—every time.** The book is built around prediction; skipping the guess turns it into a list of facts you will forget. Write your answer down, then compare.
- **Deep-read the discussions, skim the code listings.** The snippets are short and the payoff is in the explanation; the "Further Reading" links are optional unless a topic is new to you.
- **Treat the early operator and floating-point puzzles as the foundation.** Precedence, overloading, and numeric representation recur throughout; if those click, later puzzles about control flow and collections become easier.
- **Keep a personal "gotcha" list.** Note each surprise (Elvis precedence, NaN equality, initialization cycles) and revisit it before interviews or code review—these are the cases that cause real bugs.
- **Use it as a companion, not a textbook.** If you are new to Kotlin, read a structured guide first; this book assumes comfort with the syntax and rewards readers who already have intuitions to break.
【Coverage Limits】
This guide is based on stratified excerpts covering the front matter and roughly the first third of the puzzles (operators, floating point, initialization); the later puzzles on control flow, collections, lambdas, destructuring, shadowing, and extensions are known only from the table of contents and are not summarized in detail.
Excerpt 1
know the dynamic difference between members and extensions. Prepare for interviews, tests, competitions, real-world projects, and more with powered-up proble...
llowing output: It's a String with the value: nullnull Kotlin Brain Teasers Discussion Why does adding null + null produce a String ? Kotlin’s plus opera...
0.2, but your computer does its sums in binary, not decimal. To squeeze those numbers into a CPU -friendly 64 binary digits, or bits , Kotlin has to round ea...
t to read from an uninitialized property just returns null . Surprisingly, that null value then ends up being stored as the value for both properties, in spi...
non-nullable types https://kotlinlang.org/docs/null-safety.html#nullable-types-and-non-nullable-types Nullability in Java and Kotlin https://kotlinlang.org/d...
accidentally change data that’s shared with another object. What if you need to change something in an existing Event ? That’s what copy is for. To update a...
as if two plus two is five, then I’m the Queen of England . Since two plus two will never be five, the statement isn’t technically a lie. In formal logic, un...
Support this siteYour recognition and a small knowledge-service contribution help keep this technical work open source.
Scan the WeChat Pay or Alipay code below. Logged-in and guest visitors can both tip.
WeChat PayAlipay
Open WeChat or Alipay and scan. No login required.
Loading comments...
Reply to Comment
Edit Comment