Site icon TestingDocs.com

What are the new features in JDK15

Introduction

Some of the interesting new features in JDK15 are as follows:

Sealed Class
Sealed Interfaces
Text Blocks
Records
Hidden Classes

Sealed Class

https://www.testingdocs.com/questions/what-are-sealed-classes-in-java/

Sealed Interface

https://www.testingdocs.com/questions/what-is-a-sealed-interface-in-java/

Text Blocks

Textblocks are designed to support multi-line strings in the Java code. Text block begins with three double quotes and newline.

package jdk15;
//www.TestingDocs.com
public class TextBlockDemo {
    public static void main(String... args) {
        //text block begins with three double quotes and newline
        String str = """
    Hello
    Text
    Blocks
        """;
        System.out.println(str);
        String helloStr = """Hello World """; //ERROR
        String helloStr1 = """Hello
                                World 
                                """; //ERROR

    }
}

 

Exit mobile version