What Is A Sealed Class? Java 17's Powerful New Feature

preview_player
Показать описание
After java 17, it is possible to declare a class that can be inherited by only specific subclasses. We call it a sealed class. Before this feature have been arised, inheritance was an “all or nothing” situation. It means that A class could either be extended by any subclass or marked as final, which prevented its inheritance entirely.
Sealed classes are between these two extremes because they enable you to specify precisely what subclasses a superclass will allow.
Also, it is possible to declare a sealed interface in which you specify only those classes that implement the interface and/or those interfaces that extend the sealed interface.
Рекомендации по теме
Комментарии
Автор

Excellent video about implementing a custom annotation, great content, keep going!

Rozblue-kyuyrpq
Автор

The last bit about packaging should be explained with example in my opinion

SuperQaeed