CodeGym
AI Academy
Promotion
CodeGym University
Learning
Courses
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme

Lessons

  • Reviews
  • About us
Start
Start learning
Start learning now
  • My Progress
  • Courses
  • University
  • Quest Map
  • Lessons
  • enum class: values, parameters, methods, and declaration rules

    Kotlin SELF
    Level 34, Lesson 0
    We break down why Kotlin needs enum class instead of “magic strings”: type-safe values (for example, Status.DONE), standard properties name and ordinal (and why ordinal must not be used as a stable identifier), getting all options via entries, strict parsing via valueOf, as well as enums with parameters and methods (and the mandatory ; before the body). At the end — a practical example for console expense tracking and common mistakes.
    Available
  • when with enum — exhaustive branches and when as an expression

    Kotlin SELF
    Level 34, Lesson 1
    We break down how to use when with enum in Kotlin so that the compiler checks branch completeness: why an exhaustive when is better written without else, how to turn branching into a “mapping table,” how when works as an expression (returns a value), what happens to the result type, and how to properly handle null for a nullable enum ( E?).
    Available
  • Getting to Know sealed class

    Kotlin SELF
    Level 34, Lesson 2
    We break down how sealed hierarchies differ from enum class, and why sealed class is an ideal tool for modeling an “operation result” without null and “magic strings”. We will assemble a minimal CommandResult model with Ok/ Error variants, apply it in a CLI expense tracker example, and discuss common design mistakes when working with sealed results.
    Available
  • Type checks and casts: is, smart cast, as, as?

    Kotlin SELF
    Level 34, Lesson 3
    We break down how to safely work with “generic” types in Kotlin: checking a type via is/ !is, getting smart casts (including in Kotlin 2.x with the K2 compiler), and how unsafe casting as differs from safe casting as? when used together with the Elvis operator ?:. At the end: a practical example of parsing an amount from Any?, a mermaid diagram, and common mistakes.
    Available
  • sealed and when: the Ok / Error style and exhaustive handling

    Kotlin SELF
    Level 34, Lesson 4
    We break down a practical pattern for a Kotlin CLI app: a single command result via a sealed hierarchy CommandResult ( Ok/ Error), returning results from business functions without println (), and a message “dispatcher” via an exhaustive when without else. We also show separation of responsibilities: handleCommand does the work, render formats, main prints.
    Available
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning, and a Java developer’s career.
Follow us
Interface language
English
Deutsch Español हिन्दी Français Português Polski বাংলা 简体中文 मराठी தமிழ் Italiano Bahasa Indonesia 繁體中文 Nederlands 日本語 한국어 Bulgarian Danish Hungarian Basa Jawa Malay Norwegian Romanian Swedish Telugu Thai Українська Filipino Turkish Azərbaycan Русский Vietnamese
Programmers Are Made, Not Born © 2026 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2026 CodeGym