ADocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
non-sealed interface is a type declaration that explicitly opts out of the restricted inheritance hierarchy established by a parent sealed interface. By applying the non-sealed modifier, the interface re-opens the type hierarchy, allowing any arbitrary, unknown class or interface to implement or extend it without requiring explicit permission from the parent.
In Java’s sealed classes architecture, any type permitted to extend or implement a sealed parent must explicitly declare its own sealing state to maintain hierarchy control. While classes have three modifier options (sealed, non-sealed, or final), interfaces inherently cannot be final. Therefore, an interface extending a sealed interface must be declared as either sealed or non-sealed.
- Hyphenated Contextual Keyword:
non-sealedis the first and only hyphenated keyword in the Java language. It is a contextual keyword, meaning it only functions as a reserved modifier when placed in the modifier list of a class or interface declaration. - Exhaustiveness Checking: The presence of a
non-sealedinterface does not break exhaustiveness checking for pattern matching on the rootsealedtype. Aswitchexpression on the parentsealedinterface (e.g.,Shape) remains fully exhaustive as long as all permitted direct subtypes (e.g.,case Circle candcase Polygon p) are covered. Adefaultclause is not required. Furthermore, when switching directly on thenon-sealedtype itself, exhaustiveness is achieved by providing an unconditional type pattern (e.g.,case Polygon p ->), which also eliminates the need for adefaultkeyword. - Asymmetric Transitivity: The
non-sealedmodifier affects only its own descendants. It does not invalidate the sealing of its parent. The parentsealedinterface remains strictly sealed and continues to reject direct implementations from unpermitted types, while the branch originating from thenon-sealedinterface becomes entirely open.
Master Java with Deep Grasping Methodology!Learn More





