Zunda Vertical Reading Problem Java 12 Early-Access Edition

__ Original story: __

-Zunda vertical reading problem -Zunda vertical reading problem php edition


If you want to write a character string that spans multiple lines in the source code because Java has not supported a function called here document in other languages for a long time.

--Join with + earnestly. --Use String :: join. --Use some external library

It has become difficult to understand the code because it is necessary to take measures such as. In response to such criticisms and requests, Project Amber has proposed a function called Raw String Literal, which has been implemented in the Early-Access version of JDK12 as of 2018-09-28.

There are no difficult steps to try Early-Access, and it is built for each platform provided in JDK 12 Early-Access Builds. Just unzip the tar-ball. I used a tar-ball for Linux.

tar xvf openjdk-12-ea+12_linux-x64_bin.tar.gz

Then, a directory called jdk-12 will be created, so prepare the following Main.java in the same hierarchy as that directory.

Main.java


public class Main {
    public static void main(String[] args) {
        var tweet = `
I'm too busy to mess around
Lonely
Hard
        `;
        tweet.align().lines().map(line -> line.substring(0, 1)).forEach(System.out::println);
    }
}

After that, when I compiled and executed it as follows, I was able to get the expected result (´ ・ ω ・ `)

$ ./jdk-12/bin/javac --enable-preview --release 12 Main.java
Note: Main.java uses preview language features.
Note: Recompile with -Xlint:preview for details.
$ ./jdk-12/bin/java --enable-preview Main
Busy
Sa
Tsu

The detailed version information was as follows.

$ ./jdk-12/bin/java --version
openjdk 12-ea 2019-03-19
OpenJDK Runtime Environment 19.3 (build 12-ea+12)
OpenJDK 64-Bit Server VM 19.3 (build 12-ea+12, mixed mode)

reference:

Recommended Posts

Zunda Vertical Reading Problem Java 12 Early-Access Edition
[Java] Problem No. 2
[Java] Problem No.3
[Java] Problem No.1