From the course: Pattern Matching for Switch in Java 21
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Evolution of switch in Java - Java Tutorial
From the course: Pattern Matching for Switch in Java 21
Evolution of switch in Java
- [Instructor] The switch statement has been evolving a lot throughout the many Java versions. Talking about the evolution of the switch statement, initially the switch statement supported the comparison of only primitive types like int, byte, short, and char. Later, enum types were supported, making it possible to use enums as case expressions. Java 7 introduced the possibility of using string in the switch statement, making it possible to perform string matching using switch. Java 12 introduced switch expressions as a preview feature, making it possible for switch to return a value. It is important that you put a semicolon at the end of the switch block. Java 12 also eliminated the need for a break statement after each case. Instead of the break, an arrow operator was introduced. This made the syntax more concise. Switch expressions were made a standard feature in Java 14, and with this, it was possible to use switch, both as a statement and as an expression. Java 17 introduced…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.