A Tale of Two Switches a.k.a A Deep Dive into Type Switches
Type Switches are now part of Java Language albeit with the preview tag. Though similar to traditional constant switch statements in terms of structure but they differ in multiple ways – they now accept type as an expression to switch – essentially they can “switch” on a type. Switching on a type is not as straightforward as switching on constant values – now a particular type can match multiple cases, thanks to type hierarchies. What happens if such a case occur? How does the implementation take care of this? What’s the byte code generated?
Experience level:
Intermediate