The order of pattern labels is imposed by the class hierarchy and is quite strict, but we can do some changes without creating any dominance issues. For instance, since Extra and Large are subclasses of Medium, we can switch their positions. Some things apply to Jumbo and Huge since they are both subclasses of Medium […]
Month: December 2022
Dealing with pattern labels dominance in switch – Objects, Immutability, Switch Expressions, and Pattern Matching
60. Dealing with pattern labels dominance in switch The compiler matches the selector expression against the available pattern labels by testing the selector expression against each label starting from top to bottom (or, from the first to the last) in the exact order that we wrote them in the switch block. This means that the […]