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
  • Nullable as a contract: where null is justified and where it gets in the way

    Kotlin SELF
    Level 41, Lesson 0
    We look at nullable types in Kotlin as a contract: what String ? really means, when a safe call ?. and the Elvis operator ?: are the norm at the system boundary (input, parsing, lookup), and when null starts to “leak” into business logic. Using examples with toIntOrNull(), lookup in a Map, and a mini app ExpenseTracker, we learn to localize nullable usage and avoid anti-patterns like !! and sentinels ( 0, - 1, "UNKNOWN").
    Available
  • What to use instead of null: preconditions, sealed results, Result

    Kotlin SELF
    Level 41, Lesson 1
    We break down why null often turns into a “foggy contract”, and what practical replacements you can use in Kotlin: preconditions ( require/ check and the *NotNull variants), meaningful results via sealed classes (an exhaustive when), and also the standard container Result<T> for “error as a value”. Using a CLI expense tracker as an example, we show how to distribute these approaches across layers and avoid common pitfalls.
    Available
  • Smart cast and how to use it

    Kotlin SELF
    Level 41, Lesson 2
    We break down how smart cast works in Kotlin: when the compiler “promises” you a narrower type without as and without !!, why it sometimes refuses (instability of var, properties like obj . prop, lambdas, repeated reads), and which techniques help: taking a snapshot into a local val, guard clauses with return, as well as explicitly converting T? -> T via requireNotNull/ checkNotNull. At the end — a practical example with searching for an Expense? and a cheat-sheet table.
    Available
  • Removing null from collections and transformation pipelines

    Kotlin SELF
    Level 41, Lesson 3
    We cover practical “sanitation” for Kotlin collections: why List<T?> quickly infects a pipeline with checks, how to “kill” null early using filterNotNull() and mapNotNull(), how to build an input-normalization gate, carefully work with search results ( find/ firstOrNull), and convert Map<K, V?> into Map<K, V> without !!. At the end — nuances of takeIf/ takeUnless and common mistakes.
    Available
  • Designing a model without nullable fields

    Kotlin SELF
    Level 41, Lesson 4
    Let’s look at a practical approach to modeling in Kotlin: keep null at the boundary (input/external data), normalize strings via trim(), parse numbers via toIntOrNull(), return errors explicitly via sealed class ( Ok/ Error), and in the domain model use only strict types without ? and protect invariants with require(...).
    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