A sealed interface restricts which types may implement it. That closed set lets a switch cover all permitted alternatives, such as a credit or a debit, while each case binds a variable of the matching subtype. Keep behavior with the subtype that carries the data it needs.
A guarded case narrows a type match with a condition. Place specific guarded cases before a broad type pattern, or the broad pattern would already handle those values. Null needs a deliberate rule: instanceof returns false for null, and a pattern switch can name case null when absence belongs in its contract. These examples execute Java 21 patterns in the browser compiler; they don't imitate them with string labels alone. Tests cover exact boundaries and distinguish absent text from empty text.