Java 14 Arrives with a Host of New Features and will bring more features than the two previous versions combined.

The release of JDK 14 is scheduled for March 17. Version 14 includes more JEP (Java Enhancement Proposals) than JDK 12 and 13 combined. What could be most interesting for Java developers who write and maintain code on a daily basis? In a blog post, Raoul-Gabriel Urma, CEO and co-founder of Cambridge Spark, touched on a few points:

  • Improvements to switch expressions, which first appeared in Java 12 and Java 13 as a preview and are now part of Java 14;
  • Pattern matching for instanceof (a language function);
  • Useful NullPointerExceptions (a JVM feature).

According to some professionals, the classic switch instruction in Java is not great. Unlike many other parts of Java, it was not properly redesigned when the functionality of C was removed all those years ago. The key defect is the “fall by default”. This means that if you forget to put a break clause in each case, processing will continue until the next case clause.

Another defect is that the variables are extended to the entire switch, so you cannot reuse a variable name in two different case clauses. In addition, a default clause is not required, which leaves code readers in the dark as to whether or not a clause has been forgotten.

And of course, there is also the main limitation: the type to activate can only be an integer, an enumeration or a string.

As part of Project Amber, switch has benefited from a few changes! They were launched in preview in JDK 12 and again in 13 and are intended to be published in JDK 14. Developers will have a new functionality when switch is used as an instruction. In addition, it may also be used as an expression in the future.

Benefits of the new switch expressions include reduced scope for bugs due to lack of transition behavior, completeness, and ease of writing through expression and compound form.

Source : Oracle

Related Articles
Leave a Reply

Your email address will not be published. Required fields are marked *