Call for feedback -- switch expressions in JDK 12

Alex Buckley alex.buckley at oracle.com
Wed Apr 17 02:00:16 UTC 2019


An easy way to help move Java forward is to try out new features on real 
code and share your experiences. We're asking for feedback on how you 
use switch expressions, the new language feature in JDK 12:

   int numLetters = switch (day) {
       case MONDAY, FRIDAY, SUNDAY -> 6;
       case TUESDAY                -> 7;
       case THURSDAY, SATURDAY     -> 8;
       case WEDNESDAY              -> 9;
   };

   // Multiple labels per case (also allowed in switch statements)
   // No fallthrough with the -> form (also allowed in switch statements)

Do you find switch expressions useful? Is anything surprising? Did you 
turn any switch statements into switch expressions? Please let us know 
on this list, even if the answer is "Tried it. Works fine."

To enable switch expressions in your environment:
- IntelliJ IDEA 2019.1 
https://blog.jetbrains.com/idea/2019/02/java-12-and-intellij-idea/
- Eclipse 4.11  https://www.eclipse.org/eclipse/news/4.11/jdt.php#Java12
- Apache NetBeans 11.0 
https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=103091452
- jshell in JDK 12  run with `--enable-preview`
- javac in JDK 12  run with `--release 12 --enable-preview`

Alex


More information about the jdk-dev mailing list