> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Java Non-Sealed Class

A `non-sealed` class is a subclass within a sealed inheritance hierarchy that explicitly terminates the extension restrictions imposed by its `sealed` superclass. Introduced in Java 17, the `non-sealed` modifier reverts the class to Java's default, open inheritance model, allowing any arbitrary, undeclared class to extend it.

When a standard class or interface inherits from a `sealed` parent, the Java compiler mandates that the subclass explicitly declare its ongoing inheritance posture using one of three modifiers. This explicit declaration rule does not apply to `record` or `enum` types, as records are implicitly `final` and enums are implicitly `final` or `sealed`. For standard classes, the modifiers are:

1. `final`: Completely prevents further extension.
2. `sealed`: Continues the restricted hierarchy by requiring its own `permits` clause.
3. `non-sealed`: Opens that specific branch of the hierarchy to unrestricted extension.

## Syntax and Implementation

The `non-sealed` modifier must be placed before the `class` or `interface` keyword. It is the first hyphenated keyword in the Java language.

The following example demonstrates a valid single-file compilation unit. The subclasses omit the `public` modifier so they can legally reside in the same file as the public root class.

```java theme={"dark"}
// 1. Root sealed class explicitly permitting three subclasses
public sealed class Shape permits Circle, Rectangle, Polygon {}

// 2. Terminal node: Cannot be extended
final class Circle extends Shape {}

// 3. Continued sealed node: Maintains restricted inheritance
sealed class Rectangle extends Shape permits Square {}
final class Square extends Rectangle {}

// 4. Non-sealed node: Terminates the restriction for this branch
non-sealed class Polygon extends Shape {}

// 5. Unrestricted extension: Any class can now extend Polygon
// without needing permission from Shape or Polygon
class Hexagon extends Polygon {}
class Octagon extends Polygon {}
```

## Technical Characteristics

* **Hierarchy Requirement:** The `non-sealed` modifier is only valid on a class or interface that directly extends a `sealed` class or implements a `sealed` interface. Applying it to a standalone class results in a compilation error.
* **Pattern Matching Exhaustiveness:** When using pattern matching for `switch` expressions on the root `sealed` class, the compiler considers the `non-sealed` subclass as a single exhaustive branch. The compiler does not require (or expect) you to handle the infinite potential subclasses of the `non-sealed` class.
* **Interface Application:** Interfaces cannot be marked `final`. Therefore, an interface extending a `sealed` interface must be marked either `sealed` or `non-sealed`.
* **Reflection:** At the bytecode level, a `non-sealed` class does not possess the `PermittedSubclasses` attribute. Invoking `Class::isSealed` on a `non-sealed` class evaluates to `false`.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Java Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
