Q1What are Record Patterns and pattern matching for switch (Java 21), and how do they enable exhaustive, type-safe deconstruction of sealed hierarchies?
Record patterns deconstruct records in a case, pattern-matching switch binds by runtime type with guards, and over a sealed hierarchy the compiler enforces exhaustiveness so adding a case becomes a compile error you cannot miss.