Class SwitchYieldPreviewExamples
java.lang.Object
net.jrodolfo.java_evolution.java13.SwitchYieldPreviewExamples
Demonstrates the Java 13 preview refinement that introduced
yield in
switch expressions.
Java 12 previewed switch expressions and proposed using a break
statement with a value when a branch needed to produce a result. Feedback
from that preview led Java 13 to replace that design with yield.
Block branches still needed a clear way to produce a value when they
contained multiple statements.
Java 13 adjusted the switch-expression preview by adding yield. It
solves the readability problem by making the branch result explicit. Java 14
later finalized switch expressions with this design.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
SwitchYieldPreviewExamples
public SwitchYieldPreviewExamples()
-
-
Method Details
-
grade
Usesyieldwhen a switch branch needs multiple statements.- Parameters:
score- a numeric score- Returns:
- a grade label
-