Skip to main content

Types, variables, expressions, control flow, equality, and smart casts

This chapter is split into short pages. Read them in order the first time; later, use each page as a quick reference.

Simple way to think about it

A type tells Kotlin what kind of value it is handling. A variable gives that value a name. Control flow decides which code runs. After a successful type check, a smart cast lets you use the value as the checked type without writing a manual cast.

Chapter pages​

  1. Types and variables — val, var, inferred types, numbers, conversions, and immutability.
  2. Expressions and control flow — if, when, loops, ranges, and handling every state.
  3. Equality — value comparison, object identity, Compose, lists, and tests.
  4. Type checks and smart casts — is, !is, as, as?, and why some smart casts fail.
  5. Android application and interview preparation — a complete UI-state example, mistakes, interview questions, exercises, and revision checklist.

Use Next at the bottom of each page to continue.