Java 15

Text Blocks

Text Blocks

String msg = """
        {
            "name": Alex,
            "age": 42
        }
        """;

System.out.println(msg);
{
    "name": Alex,
    "age": 42
}

Escape Chars

String msg2 = """
        single \
        line \
        always""";

System.out.println(msg2);
single line always

Null Pointer

List<String> elements = new ArrayList<>();
elements.add(null);

System.out.println(elements.get(0).toLowerCase());
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "String.toLowerCase()" because the return value of "java.util.List.get(int)" is null
        at org.acme.Api.main(Api.java:88)