We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
2 parents b854d78 + fe0013b commit 9f3c382Copy full SHA for 9f3c382
1 file changed
content/language/pattern-matching-instanceof.yaml
@@ -12,11 +12,13 @@ modernApproach: "Pattern Variable"
12
oldCode: |-
13
if (obj instanceof String) {
14
String s = (String) obj;
15
- System.out.println(s.length());
+ int length = s.length();
16
+ // do something with 'length'
17
}
18
modernCode: |-
19
if (obj instanceof String s) {
- IO.println(s.length());
20
21
22
23
summary: "Combine type check and cast in one step with pattern matching."
24
explanation: "Pattern matching for instanceof eliminates the redundant cast after\
0 commit comments