Switch expressions are the enhancements in Java JDK 14. Switch statements are enhanced and improved to switch expressions.
Java SE 12 introduced switch expressions, which (like all other expressions) evaluate to a single value, and can be used in statements. It also introduced "arrow case ->" labels that eliminate the need for break statements to prevent fall through. use the new yield statement to return the value from multi line case. for a single line we can directly give the value to return without yield key.
Now in java jdk 14 switch is part of java language.
#JavaBeam #Java14NewFeatures #SwitchExpressionsInJava14 #Java
Ещё видео!