Skip to content

Commit dc92a2a

Browse files
committed
feat: update Java pattern matching instructions with finalization details and version requirements
1 parent 14eabda commit dc92a2a

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

instructions/java.instructions.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,10 @@ public record Triangle(double base, double height) implements Shape {}
148148

149149
### Pattern Matching
150150

151-
- Use `instanceof` pattern matching to combine type check and cast
152-
- Use switch expressions with pattern matching for exhaustive type dispatch
153-
- Use record patterns for destructuring
151+
- Use `instanceof` pattern matching to combine type check and cast (finalized in Java 16)
152+
- Use switch expressions with pattern matching for exhaustive type dispatch (finalized in Java 21)
153+
- Use record patterns for destructuring (finalized in Java 21)
154+
- Switch pattern matching and record patterns require Java 21+; on Java 21 these are final but primitive patterns in `switch` remain preview until Java 23+; if targeting an earlier LTS, use `--enable-preview` or guard with `instanceof` chains instead
154155

155156
```java
156157
// Pattern matching with instanceof

0 commit comments

Comments
 (0)