Consider this code:
---
public class PatternLocal {
public static boolean test(Object o) {
return o instanceof String s && s.length() > 0;
}
}
---
javac desugars the pattern test into:
---
public class PatternLocal {
public PatternLocal() {
super();
}
public static boolean test(Object o) {
return (let String s in (let /*synthetic*/ Object s$temp = o in s$temp instanceof String && (let s = (String)s$temp; in true)) && s.length() > 0);
}
}
---
The temporary variable s$temp is unnecessary here, as o is already a local variable and its value cannot change inside the pattern matching expression.
---
public class PatternLocal {
public static boolean test(Object o) {
return o instanceof String s && s.length() > 0;
}
}
---
javac desugars the pattern test into:
---
public class PatternLocal {
public PatternLocal() {
super();
}
public static boolean test(Object o) {
return (let String s in (let /*synthetic*/ Object s$temp = o in s$temp instanceof String && (let s = (String)s$temp; in true)) && s.length() > 0);
}
}
---
The temporary variable s$temp is unnecessary here, as o is already a local variable and its value cannot change inside the pattern matching expression.