java21
7 tutorials tagged “java21”.
- Exhaustive Switch with Sealed TypesCover every subtype of a sealed interface without default, so the compiler flags each switch to update when a type is added. Includes an expression evaluator.
- Handling Null in SwitchWhy switch throws NullPointerException for null, how case null and case null, default fix it, and how null behaves in instanceof and record patterns.
- Pattern Matching for Switch in JavaSwitch on an object's type with case patterns instead of instanceof chains: type patterns, case order and dominance, exhaustiveness, and how it compiles.
- Record Patterns in JavaTake a record apart in one step with a record pattern: nested patterns, var, generics, record patterns in switch, exhaustiveness and the rules.
- Sequenced Collections in JavaJava 21 added SequencedCollection, SequencedSet and SequencedMap, with one set of methods for the first and last elements and a reversed view.
- Guards in Switch (When Clause)Add a condition to a case pattern with when: guarded patterns, their order, how they affect dominance and exhaustiveness, and the rules for guard expressions.
- Virtual Threads in JavaVirtual threads (Java 21) are lightweight threads managed by the JVM, so a program can run millions of them. Learn how to create them and how they work.