Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Marcin Moskała

Rating No ratings yet

No description

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A practical, example-driven tour of Kotlin’s core language features for developers who want to write idiomatic Kotlin rather than Java-with-new-syntax. Best suited to programmers with some prior experience who want a structured foundation before moving on to advanced or multiplatform work. 【Book Arc】 - **Opening (~0%–10%)**: Positions Kotlin as a distinct language rather than “syntactic sugar on Java,” introduces tooling and the first program, and sets expectations for readers coming from Java or other backgrounds. - **Early (~10%–30%)**: Builds the fundamentals — basic types, literals, operators, strings, conditionals (`if`, `when`, `try`, loops), functions (default/vararg/infix parameters), and Kotlin’s nullability model including smart-casting and `lateinit`. - **Middle (~30%–55%)**: Moves into object-oriented Kotlin: classes, properties and encapsulation, inheritance and `open`/`override`, interfaces with default implementations, visibility modifiers, and data classes with `equals`/`hashCode`/`copy`/destructuring. - **Late (~55%–80%)**: Extends the language surface with annotations and meta-annotations, extension functions and properties (including member extensions), the collections hierarchy and mutable vs read-only types, and operator overloading conventions. - **Ending (~80%–100%)**: Closes with Kotlin’s type system as a unifying theme, tying together nullability, generics, and the design choices that distinguish Kotlin from Java. (Excerpts do not cover the final chapters in detail.) 【Book Arc note】 The progression is deliberately fundamentals → object model → language extensions → type-system synthesis, with each stage building on the previous one rather than presenting isolated features. 【Key Takeaways】 - **Kotlin is not Java with sugar** (Opening): The book argues Kotlin has its own conventions, features like coroutines and multiplatform, and a lower entry threshold — you don’t need Java to learn it. This framing matters because it shapes how you should read every later chapter. - **Nullability is a first-class design concern** (Early): Safe calls, smart-casting after null checks, `requireNotNull`/`checkNotNull`, and `lateinit` for injected properties form a coherent toolkit. Treat `null` as meaningful (“unknown result”) rather than a defect. - **Control flow is expression-oriented** (Early): `if`, `when`, and `try` are expressions; there is no `switch`, and “if-else-if” is really nested `if-else`. Understanding this prevents subtle bugs like the `printNumberSign` puzzle. - **Functions carry more weight than in Java** (Early): Default arguments, `vararg`, named arguments, infix notation, and trailing commas reduce boilerplate and improve call-site readability. Overloading is presented as a convenience tool, not a default. - **Classes are concise but explicit** (Middle): Properties with getters/setters replace public fields; `open`/`override` are required for inheritance; interfaces can hold default implementations, with `super<Interface>` resolving conflicts. Encapsulation is treated as a design principle, not syntax. - **Data classes eliminate boilerplate** (Middle): `data` generates `equals`, `hashCode`, `toString`, `copy`, and destructuring. The book recommends custom data classes over `Pair`/`Triple` and warns about destructuring order mistakes. - **Extensions are powerful but not magic** (Late): Extension functions/properties compile to static utilities and do not override members; member extensions and object-declaration extensions have specific use cases. Knowing the “under the hood” behavior prevents surprises. - **Collections and operators follow conventions** (Late): The read-only vs mutable interface hierarchy, standard creation functions, and operator overloading (arithmetic, `in`, `iterator`, indexing, `invoke`) are presented as a coherent convention system rather than ad-hoc tricks. 【Reading Tips】 - **Skim the opening framing chapters** if you already know why Kotlin exists; slow down at nullability and smart-casting, which are the most error-prone fundamentals. - **Deep-read the classes/inheritance/data-class block (~30%–55%)** — this is where Java habits most often produce non-idiomatic Kotlin. - **Treat operator overloading and extensions as reference material**: read once for concepts, then return when you encounter them in real code. - **Do the small code puzzles** (e.g., the `if-else-if` example) — they expose misconceptions faster than prose. - **Take away a mental checklist**: prefer expressions, use data classes for value objects, design nullability intentionally, and reach for extensions only when members aren’t appropriate. 【Coverage Limits】 This guide is based on stratified excerpts covering roughly the first half of the book in detail, with lighter coverage of later chapters on annotations, extensions, collections, operator overloading, and the type system. Coroutines, multiplatform, and testing chapters are not represented in the excerpts and are not assessed here.
Page 12
thermore, he is an active member of the developer community. His involvement goes from speaking at international conferences to being a mem- ber of CFP commi...
View in text
Excerpt 2
ly, 123 is not of type String, and "ABC" is not of type Int.We can confirm this using the is check. fun main() { println(123 is Int) // true println("ABC" is...
View in text
Excerpt 3
getter - the function that is used to get the current value of this field, • setter - the function that isused to setnewvalues for this field. This pattern i...
View in text
Excerpt 4
ider the following class A, which is equal Data classes 149 To learnmore about thehash table algorithmand implement- ing a custom hashCode method, see Effect...
View in text
Excerpt 5
isfied⁵⁷. fun pop(num: Int): List<T> { require(num <= size) // throws IllegalArgumentException if num > size check(isOpen) // throws IllegalStateException if...
View in text
Excerpt 6
[1] = "X" println(mutable) // [A, X, C] mutable.set(1, "Y") println(mutable) // [A, Y, C] } Checking if a list contains an element You can check if a list co...
View in text
Excerpt 7
ser is User?. Yes, the nullable variant is a separate type. There are classes that generate many more types: generic classes. The Box<T> class theoretically...
View in text
Excerpt 8
} However, Kotlin can overcome these limitations thanks to the use of inline functions with reified type arguments. This topic is covered in depth in the cha...
View in text
Tags
AI categories
Programming LanguageKotlinSoftware
Publisher: Leanpub
Publish Year: 2022
Language: English
Pages: 316
File Format: PDF
File Size: 15.3 MB
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…