News for hackers. Stuff that matters.

GavinBierman

Re:Java record pattern matching in JDK 19 on Monday May 16, 2022 @05:20AM (#31394947)
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.