exhaustive switch
A switch that the compiler has proven handles every possible value, so it needs no default branch.
In more detail
Exhaustiveness works for enums and sealed types, whose full set of values is known. Leaving out a case is a compile error, so adding a new variant forces every mapping to be updated. A default branch would hide that obligation, which is why the course omits it.
Related terms
- switch expression — A switch construct that produces a value, with one arm per case and no fall-through between them.
- sealed type — A class or interface that lists exactly which types may extend or implement it, so the compiler knows the complete family.
- enum — A type that allows only a fixed list of named values, such as admin or user.
Taught in
- Sealed Types And Exhaustiveness — Modern Java: Virtual Threads & High-Throughput Services
- Pattern Matching And Text Blocks — Modern Java: Virtual Threads & High-Throughput Services
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sealed Types, Casts And Pattern Matching — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Enums With Fields, Constructors And Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Object-Oriented Java — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Mock Exam: Sit It, Score It — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep