Core Java

Raw String Literals Support in JDK 12 Early Access Build 12

The biggest news this week in the world of Java is likely going to be the General Availability of JDK 11. However, another exciting development is the release of JDK 12 Early Access Build 12 (20 September 2018). This Early Access Build 12 of JDK 12 is significant because it includes implementations related to JEP 326 [“Raw String Literals (Preview)”] via changesets such as changeset 51713:d424675a9743 (JDK-8206981), changeset 51714:975d3636a2f9 (JDK-8200434), and changeset 51725:ccea318862ae (JDK-8210674).

JEP 326 itself displays multiple examples of how raw string literals might be applied in Java code in common situations (file paths, multi-line, regular expressions, database/SQL, and polyglot). These examples also appear in an arguably more readable format in associated JDK-8196004. These “Raw String Literals” examples can be pasted into Java classes/methods and compiled successfully against JDK 12 Early Access Build 12. For convenience, I’ve placed slightly adapted versions of these in a single Java class on GitHub.

Note that JEP 326 is a “Preview Feature“, so you must compile with the javac options --enable-preview and --release 12 or else you’ll encounter the error message, “error: raw string literals are a preview feature and are disabled by default” with a pointer to the backtick used to demarcate the raw string literal. Similarly, the code must be run with java launcher option --enable-preview to run successfully and to avoid the error message, “… UnsupportedClassVersionError: Preview features are not enabled …”

As far as I can determine, Early Access Build 12 does not include an implementation for JDK-8202442 [“String::unescape”]. Some of the library methods added to the String class related to raw string literals are part of JDK 11 and I discussed some of these in the post “Applying New JDK 11 String Methods“.

Published on Java Code Geeks with permission by Dustin Marx, partner at our JCG program. See the original article here: Raw String Literals Support in JDK 12 Early Access Build 12

Opinions expressed by Java Code Geeks contributors are their own.

Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button