54
String writeTextSmart = """
Ciao, hello
""";
System.out.println(writeTextStandard);
System.out.println(writeTextSmart);
}
}
The output is the same.
How It Works
Java 13 introduced an enhancement to make multiline strings more readable. So, text
block efficiently eliminates the concatenation of multiple strings together. The need was
to choose a way to visually text blocks and string literals: the delimiter """ was chosen.
Moreover, indentation was removed and replaced with whitespace characters.
For more
information on text blocks,
see the documentation at
https://openjdk
.java.net/jeps/378
.
2-4. The Enhancement of NullPointerException
Problem
You want to know which variable is null when a NullPointerException occurs.
Solution
Java 14 improved the NullPointerException functionalities
generated when an
error occurs.
The following is an example.
Line 1:package org.java17recipes.chapter02.recipe02_04;
Line 2:
Line 3:public class NullPointerExample {
Chapter 2 enhanCements from Java 9 through Java 17
55
Line 4: public static void main (String[] args) {
Line 5: String professor= null;
Do'stlaringiz bilan baham: