Level 1 · Apprentice0 XP
The same ideas as Java's wildcards, declared once and readable.
Step 1 / 5
ProblemYou have a list of dogs and a function that prints any list of animals. In Java it is rejected unless you remember ? extends. You also want a helper that parses JSON into a type T, but T is erased at runtime, so you end up passing User::class.java everywhere.
← → step
Before this: Error handling the Kotlin way
🛠️ Your turn
Reading is not the skill, doing is. Try for ten minutes before you open the hint. Getting stuck first is what makes the solution stick.
1.Declare interface Producer<out T> and interface Consumer<in T>. Show with real calls that a Producer<Dog> is accepted as a Producer<Animal>, and a Consumer<Animal> as a Consumer<Dog>. Then write inline fun <reified T> Any.isA() and a reified filter for a List<Any>.