Mobile development

Stage 1 · Lesson 4 of 9

Classes and data classes

Kotlin fundamentals

A class lists its properties right in the : class User(val id: String, val name: String). Classes are final unless you mark them open, which means other classes cannot extend them by default. Properties replace the getter and setter methods you may know from .

For models, use a . It writes equals, hashCode, toString, copy and destructuring for you, all from the constructor properties. copy changes one field and keeps the rest, as in user.copy(name = "Ana").

That is how you update UI state without changing the original. Use object when you want exactly one instance, and companion object for factory functions.

Common trapa data class with var properties shared between screens, which can change without anything noticing.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • GuideFree
    Kotlin Documentation

    JetBrains

    Start with the Kotlin tour, then the null safety and coroutines basics pages

  • CourseFree
    Android Basics with Compose

    Google · Beginner

    The Kotlin pathways in Units 1 to 3 teach the language with practice sets

Practise

  • Dart, TypeScript, Kotlin and Swift tracks with small exercises and free mentor feedback

Keep handy

  • Short Kotlin pages with a try-it editor for checking syntax quickly

Also worth your time

Mark this stage as not done?