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
  • Subtyping and generics: why List lifts, but MutableList does not

    Kotlin SELF
    Level 36, Lesson 0
    We break down how subtyping works in Kotlin for generic types: why List<Expense> can be safely used as List<Transaction>, but MutableList<Expense> cannot be lifted to MutableList<Transaction>. With examples, we show invariance of containers ( Box<T>), covariance of read-only collections, compiler errors, and practical API design techniques (accept List if you do not need to mutate), as well as intuition via function types (Transaction) -> String.
    Available
  • Declaration-site variance: out and in in your generic types

    Kotlin SELF
    Level 36, Lesson 1
    We break down declaration-site variance in Kotlin: how to declare covariant producer types with out and contravariant consumer types with in, why the compiler forbids unsafe operations (for example, var with a type parameter), and how this relates to familiar types like List, Comparable, and function types (A) -> B. At the end: a practical refactoring (report source + printer) and a list of common design mistakes.
    Available
  • Type projections: safe Array<out/in> and projections for MutableList

    Kotlin SELF
    Level 36, Lesson 2
    We break down why Array<T> in Kotlin is invariant, why casts via as are dangerous, and how use-site variance (type projections) “trims” the reference API down to a safe mode: out for reading (producer) and in for writing (consumer). We reinforce this with examples of copying arrays and contracts for MutableList, including a practical scenario with financial operations.
    Available
  • Star-projection *: List<*>

    Kotlin SELF
    Level 36, Lesson 3
    We break down star-projection * in Kotlin using List<*> and MutableList<*> as examples: what “unknown type” really means, why when reading the elements become Any?, why writing to MutableList<*> is forbidden (the logic of in Nothing), how to apply checks like is List<*>, and how the asterisk relates to out/ in projections. At the end, we’ll cover practical examples and common mistakes.
    Available
  • Type erasure and inline/reified: is T, as? T, and T::class checks

    Kotlin SELF
    Level 36, Lesson 4
    We break down why generic types are “erased” on the JVM ( type erasure), which is why checks like is T and List < Int > are forbidden, and how to legally perform checks/casts via inline + reified. In practice, we write universal utilities with as?, use T::class for messages, and collect elements of the desired type from List < Any >.
    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