Sealed classes—defined and implemented by JEP 409, as a standard language feature in Java 17—let you define hierarchies that accurately capture the knowledge of your business domain. By doing so, you can clearly define the code that handles the subclasses in a deliberate way, rather than defining generalized code that handles the unexpected classes in an unwanted manner.
In Mala Gupta’s article, you’ll learn what sealed classes are, why you need them, and how they will help improve your applications.
Take care, Alan Zeichick Editor in Chief, Java Magazine @zeichick
P.S. Did you know that Oracle produces a monthly newsletter about general application development? It covers cloud native coding, middleware, databases, Kubernetes, Oracle Application Express (APEX), DevOps, and open source initiatives. Sign up here.
The newest articles
Fight ambiguity and improve your code with Java 17’s sealed classes Declaring a class or interface as sealed enables you to control the classes or interfaces that can extend or implement it. As Mala Gupta explains, the goal of this language feature is to let you control the possible hierarchies in your business domain in a declarative manner. Read why this can be important.
BYOTE, Part 2: Test your own custom test engine for JUnit 5 In part 1 of this series, you built a simple web smoke test engine. In part 2, Matthias Merdes and Johannes Link show you how to test WebSmokeTest to make sure it is valid. You’ll also read interviews of test-engine creators who share their experiences in building real-world engines.
Is Java SE open source software? The short answer is ‘yes.’ In more than a decade of Java stewardship, Oracle has been fully committed to open source, taking Java from powerful but closed software to an open source language suitable for running the world’s most important applications. It’s been a winding road to fulfill the commitment, but as Mitch Wagner writes, it’s a journey that will deliver results for generations to come.
JUG spotlight: The Nederlandse Java User Group Participation in Java user groups (JUGs) can be extremely rewarding on both a personal and professional level. The Nederlandse Java User Group (NLJUG) has 5,000 members and offers regular meetings, a two-day developer conference, a quarterly magazine, and even the Masters of Java awards.
Java Magazine is a deep dive into Java and the JVM. Find detailed explanations about the language and the platform written by experts and members of the Java development team.
Join a quarter of a million subscribers in getting useful, authoritative programming information delivered directly to your inbox.