Monday, December 9, 2019

Java 13 - Switch Expressions

JDK 13 was released on September, 2019. One of the new feature is: Switch Expressions (Preview)

This is a preview language feature in JDK 13. It's a new feature of the Java SE Platform that is fully implemented and yet impermanent. This may become permanent in a future Java SE Platform.



Java 13 Switch Expression, Example:


java,switch,switch statement,java programming,java tutorial,java switch,switch expression,java switch expressions,java switch case,java switch statement,learn java,java 12 switch expression,java switch example,java13 switch expression,what are java switch expressions,switch in java,java (programming language),java programming tutorial,java tutorial for beginners,java 13 switch,switch statements,switch case java


Notice: You don't have to use breaks statement syntax,



You can just do,



yield - new keyword to return a value from switch expression



Another way,





In order to use preview feature you need to enable it, otherwise you will get the following error:



IntelliJ IDEA v2019.3 support  preview feature




Enable Preview feature - IntelliJ 


Open File => Project Structure. Under Project language level, choose: 13 (Preview) - Switch expressions, text blocks.
























No comments:

Post a Comment

JVM Crashes

Case Study - I gonna write a true story that happened on a company which I work for. I got a task: Crash Hunting Me: Who Crash? QA: Th...