Loading lesson…
Level 1 · Apprentice0 XP
Model a closed set of cases and let the compiler check you handled all of them.
Step 1 / 5
ProblemA method handles payment results with a chain of if (x instanceof Paid) { Paid p = (Paid) x; ... }. A new result type is added. The chain silently falls into the final else and returns a wrong message.
← → step
Before this: Streams and Optional
🛠️ 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.Model a shape as a sealed interface with records Circle, Rectangle and Triangle. Write area(Shape) with a switch and no default. Then add a Square record and let the compiler lead you to what must change.