Kotlin in Action guides experienced Java developers from the language basics of Kotlin all the way through building applications to run on the JVM and Android devices.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
# Kotlin in Action — Reading Guide
## 【One-Line Pitch】
A practical, example-driven guide for experienced Java developers who want to master Kotlin for JVM and Android development, written by two core members of the Kotlin team at JetBrains. If you already know Java and want to learn why Kotlin is more concise, safer, and more expressive—without wading through beginner programming material—this is your book.
---
## 【Book Arc】
- **Opening (~0%–10%)**: Introduces Kotlin's philosophy—pragmatic, concise, safe, and tooling-friendly—and explains why the language was created, including its static typing benefits (performance, reliability, maintainability) and how type inference reduces boilerplate.
- **Early (~10%–23%)**: Covers language fundamentals: variables, functions, classes, properties, enums, and the `when` expression. Shows how Kotlin eliminates Java boilerplate (getters, setters, constructor assignments) and introduces smart casts and expression-bodied functions.
- **Early (~23%–32%)**: Continues with control flow—`while`, `for`, and `try` as expressions—and explains Kotlin's decision to drop checked exceptions, treating exceptions uniformly and making `try` return values.
- **Middle (~32%–42%)**: Focuses on defining and calling functions: named arguments, default parameter values, extension functions, and destructuring declarations. Shows how these features make APIs more readable and idiomatic.
- **Middle (~42%–48%)**: Explores strings and regular expressions (with Kotlin's improved `split` API), then transitions into classes, objects, and interfaces—covering open/abstract classes, smart casts, and access modifiers.
- **Late (~48%–100%)**: Advances into higher-order functions, generics (including reified type parameters and variance), annotations, and reflection—culminating in a complete JSON serialization/deserialization example that ties together many language features.
---
## 【Key Takeaways】
- **Kotlin prioritizes conciseness without sacrificing readability** (Early): The language eliminates Java boilerplate like getters, setters, and explicit type declarations through properties and type inference, so code expresses intent rather than structure. This matters because developers spend more time reading than writing code.
- **`when` replaces `switch` with more power and safety** (Early): Unlike Java's `switch`, Kotlin's `when` is an expression that returns a value, requires no `break` statements, and supports combining multiple values in one branch—eliminating a common source of bugs.
- **Kotlin treats exceptions uniformly—no checked exceptions** (Early): The language drops Java's checked/unchecked distinction based on real-world experience that checked exceptions often produce meaningless rethrow/catch boilerplate without reliably preventing errors.
- **Extension functions let you add methods to existing classes** (Middle): You can define `joinToString` as an extension on `Collection<T>` and call it like a member function, even restricting it to specific types like `Collection<String>`. This is syntactic sugar over static calls but dramatically improves API usability.
- **Named arguments and default values make function calls self-documenting** (Middle): Instead of `joinToString(collection, " ", " ", ".")` with unclear string parameters, Kotlin lets you write `joinToString(collection, separator = " ", prefix = " ", postfix = ".")`, eliminating guesswork and the need for IDE lookups.
- **Smart casts work reliably because classes are final by default** (Middle): Since properties can't be overridden unless explicitly marked `open`, Kotlin can safely cast after type checks without explicit cast syntax—improving expressiveness while maintaining safety.
- **Kotlin strings are Java strings—no conversion needed** (Middle): The language adds extension functions to improve the standard Java `String` API, such as replacing the confusing `split(".")` regex trap with overloads that require explicit `Regex` types.
- **Generics and reflection enable powerful metaprogramming** (Late): Reified type parameters allow runtime type checks that Java erases, and the reflection API (`KClass`, `KProperty`) supports building frameworks like the book's complete JSON serializer—showing how language features compose for real-world tooling.
---
## 【Reading Tips】
- **Skim the opening philosophy sections (~0–10%)** if you're already convinced Kotlin is worth learning; the real value starts with concrete syntax in Chapter 2. But do read the tooling discussion—it explains why IDE support is integral to Kotlin's design.
- **Deep-read the function and extension sections (~32–42%)**: These features (named arguments, defaults, extensions, destructuring) are what make Kotlin code feel dramatically different from Java. Practice converting Java utility methods into Kotlin extensions.
- **Pay special attention to the `when` expression and smart casts (~19–23%)**: These are Kotlin idioms you'll use constantly. The enum + `when` example is a pattern you'll apply to sealed classes and state machines.
- **The generics chapter (~48%+) is the hardest part**: Variance, contravariance, and star projections are genuinely tricky. Skim the theory first, then focus on the JSON serialization example to see how it all fits together in practice.
- **Use the Java-to-Kotlin converter as a learning tool**: The book mentions this IntelliJ IDEA feature—run it on your own Java code to see idiomatic Kotlin transformations, then study why each change was made.
---
## 【Coverage Limits】
This guide covers the book's progression through language fundamentals, functions, classes, and advanced features like generics and reflection. The excerpts do not cover Android-specific development, coroutines, or the Kotlin/Native and Kotlin/JS platforms in detail.
---
##
Page 13
d KProperty 265 ■ Implementing object serialization using reflection 268 ■ Customizing serialization with annotations 270 JSON parsing and object deserializa...
View in text
Excerpt 2
e source code to the smallest number of characters possible. For example, even though Kotlin supports operator overloading, users can’t define their own oper...
View in text
Excerpt 3
read from the file. Listing 2.28 Using try as an expression fun readNumber(reader: BufferedReader) { val number = try { Integer.parseInt(reader.readLine()) B...
View in text
Excerpt 4
se it’s not relevant to any other places where User is used. If you follow this approach the API of the class contains only the essential methods used everyw...
View in text
Excerpt 5
using them as keys in hash-based containers such as HashMap toString for generating string representations showing all the fields in decla- ration order The...
View in text
Excerpt 6
a >>> val errors = listOf("403 Forbidden", "404 Not Found") >>> printMessagesWithPrefix(errors, "Error:") Error: 403 Forbidden Error: 404 Not Found Functiona...
View in text
Excerpt 7
sting 6.4 Using the Elvis operator to deal with null values fun strLenSafe(s: String?): Int = s?.length ?: 0 >>> println(strLenSafe("abc")) 3 >>> println(str...
View in text
Excerpt 8
rface requires the process function to return a value; and, because the Unit type does have a value, it’s no problem to return it from the method. But you do...
View in text
Tags
AI categories
Programming LanguageBackendandroid
Text Preview (First 20 pages)
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Generating text preview…
Loading comments...
Reply to Comment
Edit Comment