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? This talk will discuss these answers in detail with code.
Type switches also bring along with them a lot of compile-time dos and don’ts – these don’ts translate to compilation errors. Talk will cover some of the major ones in detail with explanation of why the rule is there in the first place. The code generation uses latest bootstrap mechanism which is a major difference when compared to classical switches. Talk would do a deep dive in to the generated byte-code to provide the programmer an internal view of the implementation.
Type Switches are now part of Java language as part of the switch pattern in the preview mode - They are in the third preview stage for Java 19 and expected to become a standard feature in the following version.
Fair amount of Java programming is the only pre-requisite for the attendees. No familiarity with byte code is assumed.
Attendees would be able to
- understand type switches - what, how and where to use them.
- appreciate some of compiler rules much more due to a better understanding of internals.
- differentiate the two switch constructs in terms of expected outputs so as to program more effectively.