What's new in Java 17
Java 17 is an LTS release, meaning that, depending on the vendor, it will be supported for more than 5 years (up to 10, in some cases). It was released in September 2021.
Let's look at some of the new features introduced with this version.
Sealed classes
Sealed classes were introduced with Java 15, and the feature became officially supported with Java 17. They provide a way to declaratively define classes and interfaces while restricting which objects can extend it or implement such classes and interfaces.
This can be particularly useful in specific cases, such as if you are defining an API, as you can, at design time, control some aspects of the usage of APIs.
Here is a simple example:
public sealed class Payment permits Instant, Wire, CreditCard […]
In this example, we declare a Payment
class, and we define that only Instant
, Wire
, and CreditCard
can extend it. In this particular example, we suppose these classes...