Introduction of the new generation Java programming guide (Java language extension project "Amber" edition)

This article is a continuation of Introduction to the New Generation Java Programming Guide (Java 12).

Java language extension project "Amber"

The book concludes with a commentary on the Amber project. The Amber project is an effort to extend the Java language to a better language, but at the time of publication of the original, it seems that there were many undecided versions of Java that could be used. Of course, there are still some undecided translations that have been released. Although it is an Amber project that includes such ** future functions **, the book explains the following five.

Functions that can be used with Java 14

Unlike when the book was released, Java 14 has already been released. Of the above features in Java14

Can be used as a Preview function.

Text block

Of the above, the one I personally want to officially release as soon as possible is the text block. The text block feature has been released as a Preview version from Java 13, but it has not yet been officially released in Java 14 and is expected to be officially released in Java 15. When defining a string literally in Java, enclose it in double quotes ("). In a text block, you can define line breaks, double quotes, etc. without using escape sequences by enclosing the string in three double quotes ("" ").

For example

<HTML>
    <BODY>
        <H1>Meaning of life</H1>
    </BODY>
</HTML>

Until now to define a character string such as

String html = "<HTML>" + 
"\n\t" + "<BODY>" + 
"\n\t\t" + "<H1>Meaning of life</H1>" +
"\n\t" + "</BODY>" +
"\n" + "</HTML>";

I was doing like

String html = """
              <HTML>
                  <BODY>
                      <H1>Meaning of life</H1>
                  </BODY> 
              </HTML>
              """;

Can be written simply. You may be concerned about the indentation, but the same amount of whitespace as before the three closing quotation marks ("" ") is removed from the beginning of each line. As a result, you can generate the first string shown. In this way, the Amber project, which is proceeding with various useful functions, is summarized in an easy-to-understand manner, and I think that you can see how the Java language will evolve in the future just by reading it quickly.

This is the introduction of the new generation Java programming guide (Java language extension project "Amber" edition).

Recommended Posts

Introduction of the new generation Java programming guide (Java language extension project "Amber" edition)
Introduction of New Generation Java Programming Guide (Java 10)
Introduction of New Generation Java Programming Guide (Java 11)
Introduction of New Generation Java Programming Guide (Java 12)
Java Programming Style Guide for the Java 11 Era
Output of the book "Introduction to Java"
The story of learning Java in the first programming
Memorandum of new graduate SES [Java object-oriented edition]
I touched on the new features of Java 15
[Introduction to Java] List of things that got caught by the 14th day of programming
Java language from the perspective of Kotlin and C #
Introduction to Java for beginners Basic knowledge of Java language ①
Reintroduction to Java for Humanities 0: Understanding the Act of Programming