We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f439f9c commit bbb0fe5Copy full SHA for bbb0fe5
docs/bugpattern/PatternMatchingInstanceof.md
@@ -0,0 +1,28 @@
1
+Pattern matching with `instanceof` allows writing this:
2
+
3
+```java
4
+void handle(Object o) {
5
+ if (o instanceof Point(int x, int y)) {
6
+ handlePoint(x, y);
7
+ } else if (o instanceof String s) {
8
+ handleString(s);
9
+ }
10
+}
11
+```
12
13
+which is more concise than an instanceof and a separate cast:
14
15
16
17
+ if (o instanceof Point) {
18
+ Point point = (Point) o;
19
+ handlePoint(point.x(), point.y());
20
+ } else if (o instanceof String) {
21
+ String s = (String) o;
22
23
24
25
26
27
+For more information on pattern matching and `instanceof`, see
28
+[Pattern Matching for the instanceof Operator](https://docs.oracle.com/en/java/javase/21/language/pattern-matching-instanceof.html)
0 commit comments