


A preview language feature in Java 14, Records is in its second preview in Java 15, with a few changes. RecordsĪ new type of class, Records introduced a compact form to model value objects. Let’s move on to the next enhancement in Java 15 – the introduction of local records. Let’s model the plant hierarchy as follows (I’m not detailing the classes on purpose): class Plant Depending on the type of plant, a gardener might need to do different activities. Imagine you are creating an application that helps its users with gardening activities. But why would you need to create restricted hierarchies? Need for creating restricted hierarchies On the one hand, it lets you reuse a class with inheritance, and on the other hand, it lets you restrict which classes can extend it.

Sealed classes and interfaces (a preview language feature)īy defining a class as a sealed class, you can explicitly define which other classes can extend it. In this article, I will cover all the new and updated language features in Java 15, why you need them, and I’ll show you how to use them in IntelliJ IDEA. There are no changes to Text Blocks from Java 14. Introduced in Java 13, Text Blocks are being added to Java 15 as a standard language feature. Pattern Matching for instanceof, introduced as a preview language feature in Java 14, is in its second preview in Java 15, without any changes. Java 15 also modifies the preview language feature Records, introduced in Java 14, and enhances the interfaces and enums you are used to working with. This language feature is introduced as a preview language feature. The goal is to let you define the possible hierarchies in your business domain in a declarative manner, so that it is easier to process them. The language syntax allows you to restrict the classes or interfaces that can extend or implement other classes or interfaces. Java 15 introduces a new language feature – sealed classes and interfaces.
