While Java Development Kit (JDK) 11 won’t arrive for another month, work proceeds on its successor, JDK 12, with two experimental (beta) capabilities proposed so far for the release, expected in March 2019: switch expressions and raw string literals.
JDK 12 is now in development in the OpenJDK community.
As Java builders move to support pattern matching, existing irregularities of the existing
switch statement become impediments. These include the default control flow behavior of switch blocks; default scoping of switch blocks, in which the block is treated as one single scope; and switch working only as a statement. The current design of Java’s
switch statement follows closely languages such as C++ and, by default, supports fallthrough semantics. This control flow has been useful for writing low-level code. But as switch is used in higher-level contexts, its error-prone nature begins to outweigh flexibility.
Raw string literals
Raw string literals would span multiple lines of source code while not interpreting escape sequences, such as
n, or Unicode escapes, of the form
/uXXX. Java’s builders have multiple goals for this capability, including:
- Making it easier to express a sequence of characters in a readable form, without Java Simplification in supplying strings targeted for grammars other than Java.
- Supplying strings that span several lines of source code without having special indicators for new lines.
- The ability to express the same strings as traditional string literals, except for platform-specific line terminators.
- Library support to replicate the current javacstring-literal interpretation of escapes and manage left-margin trimming.
Java 12’s developers say real-world Java code needs a mechanism for capturing literal strings as is, without special handling of Unicode escaping, backslash, or new lines. A raw string literal sets aside both Java escapes and Java line terminator specifications, providing character sequences that in many circumstances are more readable and maintainable than the existing string literal.
Java has remained one of the few languages without language-level support for raw strings. The proposal would not introduce any new string operators. Also, raw string literals also do not directly support string interpolation. There would be no change in the interpolation of traditional strings.
This story, “JDK 12 roadmap: Java 12 gets first targeted features” was originally published by
Share this post if you enjoyed! 🙂