2 ms·
This is all true, but with pattern matching for instanceof you don't need the explicit cast: Object foo = ... if (foo instanceof String s) { Sy
by GavinBierman 4y ago
This is all true, but with pattern matching for instanceof you don't need the explicit cast:
Object foo = ...
if (foo instanceof String s) {
System.out.println(s.toLowerCase())
}
In this case, the scope of the pattern variable `s` is just the then block, so are free to reuse it elsewhere in the block.