What is a Sealed Class/Interface ?
Hello Folks,
Java version 17 has been released around 15 days ago in Sept, 2021. There are a number of features that have been added to the Java language, some have been removed as well though.
Today, we are going to talk about one such feature added to the language - "Sealed" classes or interfaces.
What exactly is the concept of Sealed?
Sealed classes and interfaces restrict which other classes or interfaces may extend or implement them.
This feature was actually added as a preview feature with JDK15. With JDK16, it was further refined but remained as a preview feature.
With JDK17, the feature has finally arrived without any change from JDK16.
Are you interested in knowing why do we need actually such classes/interfaces? Let's not try to learn everything in one go :) and discuss about it in next article. Till then, stay tuned !
PS: A preview feature is?a new feature whose design, specification, and implementation are complete, but which is not permanent, which means that the feature may exist in a different form or not at all in future JDK releases.
Thanks for reading this far!