String reboot (plain text)
Alex Buckley
alex.buckley at oracle.com
Fri Apr 5 18:12:50 UTC 2019
On 4/5/2019 7:15 AM, Jim Laskey wrote:
> Following example works as expected:
>
> public class Test {
> public static void main(String... args) {
> String result = """
> public class Main {
> public static void main(String... args) {
> System.out.println("Hello World!");
> }
> }
> """.align();
> System.out.println(result);
> }
> }
>
> Empty string is both "" and """""". Escape sequences and unicode escapes are always translated.
As someone who was nervous about how raw string literals effectively
sidelined Unicode, I'm pleased that \uXXXX escapes are back. It's also
great that the traditional escape sequence \" will be interpreted as a
single " like it would be in a traditional string literal. Because, as
we all know, the code above started life as this painful noisy code:
String result = "public class Main {\n" +
" public static void main(String... args) {\n" +
" System.out.println(\"Hello World!\");\n" +
" }\n" +
"}\n";
Now a developer can move forward in steps: today remove all the
end-of-line cruft involving \n and + that multi-line strings do for
free, and don't worry about mid-line escape sequences such as \" --
convert them to " tomorrow, or next week, or not at all, your choice.
Alex
More information about the amber-spec-experts
mailing list