The Missing
Kotlin Reference

Learn to program in Kotlin, starting from the basics.

Contents

Index of terms

Part 1: Writing Kotlin

From one download to a real program, using the tools Kotlin actually gives you.

  1. 1Installing IntelliJ, and your first projectcoming soonOne download. A JDK and the Kotlin compiler come with it.
  2. 2Your first program, and your first red squigglecoming soonmain, println, the Run window, and the command IntelliJ really ran.
  3. 3val, var, and types you rarely writecoming soonImmutable by default, and what type inference is doing for you.
  4. 4Stringscoming soonTemplates, raw strings, and the standard library that comes with text.
  5. 5Numberscoming soonInt, Long, Double, and Kotlin refusing to widen one into another for you.
  6. 6Reading inputcoming soonAsking the reader a question, and the type Kotlin hands back.
  7. 7Null safetycoming soonWorking with a value that might not be there, without pretending it always is.
  8. 8Deciding thingscoming soonif is an expression here, and when is what you reach for instead.
  9. 9Loops and rangescoming soonCounting up, counting down, and stepping through a range.
  10. 10Functionscoming soonDefault arguments, named arguments, and functions that fit on one line.
  11. 11Debuggingcoming soonA wrong answer with no error, and the tools for finding out why.
  12. 12Listscoming soonHolding many values, and the difference between reading one and changing it.
  13. 13Transforming collectionscoming soonDescribing what you want from a list instead of looping over it.
  14. 14Maps and setscoming soonLooking something up by name, and the answer that might not exist.
  15. 15Data classescoming soonTwenty lines you do not write, and how to go and look at them.
  16. 16Classes and propertiescoming soonBuilding your own types, and why Kotlin has properties instead of fields.
  17. 17Sealed classescoming soonDescribing every state a thing can be in, and the compiler holding you to it.
  18. 18Errorscoming soonWhat happens when something goes wrong, and deciding what to do about it.
  19. 19Filescoming soonReading and writing a file, so a program survives being closed.
  20. 20Extension and scope functionscoming soonThe idioms that make Kotlin code look like Kotlin.
  21. 21Splitting a program upcoming soonPackages, several files, and deciding what the rest of the program may see.
  22. 22Build something realcoming soonNo new syntax. One project, built in stages, using everything so far.

Part 2: Lifting the floor

What is underneath the language you have been writing, and why it is shaped this way.

  1. 23What actually runs your Kotlincoming soonThe JVM, class files, and reading the bytecode your own code compiles to.
  2. 24References and identitycoming soonTwo names for one thing, and the difference between equal and the same.
  3. 25Memory and garbage collectioncoming soonNothing to free, and the leaks that happen anyway.
  4. 26Where null came fromcoming soonThe Java underneath, platform types, and why !! is in the language at all.
  5. 27Boxingcoming soonInt, Integer, and what a nullable number quietly costs.
  6. 28Genericscoming soonWriting code that works for any type, and what the JVM forgets at runtime.
  7. 29Interfaces, objects and delegationcoming soonSharing behaviour between types, and handing a job to someone else.
  8. 30Sequences versus collectionscoming soonThe chain of five operations that quietly built five lists.
  9. 31Gradlecoming soonThe build file that has been sitting in your project since chapter 1.
  10. 32Coroutinescoming soonDoing more than one thing at once, and the first library the book adds.
  11. 33Where to go nextcoming soonAndroid, the server, multiplatform, and what this book left out on purpose.