Kotlin
ver. 1.0.0
A practical, idiomatic tour of Kotlin: syntax, types, functions, functional patterns, interop, and advanced language conventions for building readable, safe, and extensible code.
This node is a practical, idiomatic introduction to Kotlin covering its design goals, core syntax, types, functions, and library-oriented features. It shows how to write concise, safe, and interoperable Kotlin: reading small programs, organizing and extending functions, working with classes/data classes/objects, using lambdas and collection transformations (eager and lazy), handling nulls and platform types, and applying Kotlin’s naming conventions (operators, indexing, destructuring, delegates). The material also covers generics, function types (including inline semantics), annotations and reflection, and how to build readable DSLs.
This comprehensive node presents Kotlin from first principles through advanced, idiomatic usage. It begins with Kotlin’s character and commitments — pragmatic, concise, safe, and interoperable — and explains how Kotlin compiles to JVM bytecode with a small runtime. From there it teaches the core syntax you need to write small programs: functions (expression and block bodies), val/var, string templates, classes and properties (including computed properties), enums and exhaustive when, smart casts, loops and control flow, and exception handling with try-as-expression.
Function and API design is emphasized: top-level and local functions, named arguments, default values, varargs and spread, infix notation, extension functions and properties (and why they aren’t virtual), and organizing helpers so code reads well and interoperates with Java. You learn Kotlin’s declaration and inheritance model: final-by-default classes, open, visibility modifiers (including internal), constructors and init blocks, interface properties/backing fields, sealed classes for exhaustive matching, delegation with by, data classes, and the three object forms (singletons, companions, anonymous objects).
Functional and collection idioms are covered in depth: concise lambdas and member references, collection transformations (filter/map/flatMap and query helpers), eager vs lazy processing with Sequence, and Java SAM interop. Function types are treated fully: declaring, passing, returning, nullable/default function parameters, inline functions to remove runtime overhead, resource-management patterns using inline lambdas, and lambda return semantics (non-local, labeled, anonymous).
Kotlin’s type system is explained for safety and interop: nullability encoded in types and operators (?., ?:, as?, !!), tools like let/lateinit/nullable receivers, platform types crossing the Java boundary, primitives and boxing, Any/Unit/Nothing, and the distinction between read-only and mutable collection interfaces (plus when to use arrays and primitive arrays). Generics and JVM erasure are described with practical workarounds: declaration-site and use-site variance (out/in), star projections, and reified inline type parameters to recover runtime type information.
You also learn how Kotlin maps syntax to conventions you can implement: operator overloading, equals/compareTo for == and ordering, get/set/contains/rangeTo/iterator to enable indexing, membership, ranges and for-loops, componentN functions for destructuring (and data classes supplying them), and property delegation via getValue/setValue (with standard delegates and map-backed properties).
Finally, the node covers annotations and reflection (KClass, KCallable, KFunction, KProperty), how to control annotation targets/retention and pass compile-time constants, and practical reflection use (example: runtime JSON serialization and callBy construction). It closes with designing and recognizing DSLs: internal vs external DSLs, lambdas with receivers for nested, declarative builders, operator invoke for callable objects, and composing extension/infix/member functions to create readable APIs — plus guidance on when to design a DSL versus a plain API.
Taken together, these units give you the language fundamentals, idioms, and advanced techniques to write concise, safe, performant, and expressive Kotlin code that interoperates smoothly with Java and scales from small scripts to production servers, Android apps, libraries, and DSLs.
Units
Kotlin: What and Why 3/4
Introduction to Kotlin: concise, safe, pragmatic, statically typed with inference, enriched by functional ideas, suited to server/Android/DSLs, and compiled to JVM bytecode.
Kotlin Basics 3/4
Core Kotlin syntax: functions, variables, classes/properties, control flow, loops, and exceptions
Defining and Calling Functions 3/4
Make Kotlin functions easy to call, place, and extend — including top-level and extension functions, defaults, varargs, infix notation, string utilities, and local helpers.
Classes, Objects, and Interfaces 3/4
Declare Kotlin types, control inheritance and visibility, use constructors, data classes, delegation and object forms
Programming with Lambdas 3/4
Learn idiomatic Kotlin lambdas, collection transformations (eager and lazy), Java SAM interop, and lambdas with receivers
The Kotlin Type System 3/4
Kotlin’s type system: null-safety, primitives/boxing, special types, and collection mutability — including how Java interop affects them.
Operator Overloading and Other Conventions 3/4
How Kotlin maps familiar syntax to named conventions you can implement — operators, indexing, destructuring and property delegates
Higher-Order Functions: Lambdas as Parameters and Return Values 3/4
How to write, pass, return, and optimize function types and lambdas in Kotlin, including inline behavior and return semantics.
Generics 3/4
Understand and use generics: declaration, JVM erasure and its workarounds, and variance (out/in) with star projections and reified types.
Annotations and Reflection 3/4
Use Kotlin annotations and reflection to inspect, customize, serialize, and construct types you don’t know at compile time.
DSL Construction 3/4
How to design and read Kotlin domain‑specific languages by composing language features into structured, readable APIs