JEP 406 is a Java Enhancement Proposal (JEP) that was issued by the OpenJDK Community, the open-source organization responsible for developing the Java Development Kit (JDK). JEP 406 specifically proposes the addition of a new feature to the Java language called “pattern matching for switch,” which allows developers to use a more concise and readable syntax when checking the type of an object at runtime. The syntax for this feature is similar to the syntax used for pattern matching in other programming languages, such as functional languages like Haskell.

Here is an example of how the “pattern matching for switch” feature might be used:

Java 14 – Switch Expressions Click To Tweet

Syntax –

 

Example – If Else – before Java 17

 

Example – If Else – Java 17

 

Example – Pattern matching and null – before Java 17

 

Example – Pattern matching and null – Java 17

 

NOTE:

If you want to go deep into learning JEP 406 and want to see more examples, then please visit JEP 406: Pattern Matching for switch (Preview)

Java 14 – Switch Expressions Click To Tweet
convert intstream to integer array

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester. He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

close

Enjoy this blog? Please spread the word :)

Follow by Email
Twitter