Raw String Literals Revisions

Jim Laskey james.laskey at oracle.com
Mon Feb 5 16:58:48 UTC 2018

Based on input received since the reveal of https://bugs.openjdk.java.net/browse/JDK-8196004
Raw String Literals, we propose making the following changes.

- We will be extending the definition of raw string literals to allow
  repeating backticks (ala Markdown.)
  - A raw string literal will begin with a sequence of one or more
    backticks,  The raw string literal will end when a matching sequence of
    backticks is encountered. Any other sequence of backticks is treated
    as raw characters.
  - There will no longer be an empty raw string literal (redundant and
  - There will no longer be a need for a embedded backtick sequence (double

    String a = `xyz`;              // "xyz"
    String b = ``xyz``;            // "xyz"
    String c = ```x`y``z```;       // "x`y``z"
    String d = ``;                 // unmatched opening raw string sequence?
    String e = ``
               WHERE `CITY` = ‘INDIANAPOLIS'
               ORDER BY `EMP_ID`, `LAST_NAME`;
    String f = ```````````````````````````````````````````````
               WHERE `CITY` = ‘INDIANAPOLIS'
               ORDER BY `EMP_ID`, `LAST_NAME`;

- The naming of the the “escape" and “unescape" String methods will be
  reversed such that “unescape" converts escape sequences to characters
  and “escape" converts worthy characters to escape sequences. Some more
  thought could be given to these names 1) to address the overloaded use
  in other languages, ex. JavaScript HTML escaping, 2) truly make the
  direction of conversion clear.

- There was some good discussion about allowing multi-line traditional
  strings. The best argument was using the multi-line traditional strings
  as a stepping stone to multi-line raw strings; simple -> multi-line ->
  raw. It was also mentioned that multi-line traditional strings would
  lessen the need for the unescape/escape methods.
  String g = "
              public class Example{  
                public static void main(String... args){  
                  System.out.println(\"Hello World\");  
  Ultimately, ignoring escapes, we would end up with two ways of do the
  same thing. Thus, we will not be supporting multi-line traditional
  strings at this time.

I will be updating the JEP accordingly.


— Jim

More information about the amber-spec-observers mailing list