Hi all, I've taken a look where in my source code I can use instanceof Point(var x, var y) instead of instanceof Point p. I've discovered that i've a lot of occurrences where i only need some record components but not all of them, by example, i've an AST that defines the declaration of a variable like this record LocalVarExpr(String name, Expr init) implements Expr { }
When i want to some analysis, i've a code like this: Env env = ... if (expr instanceof LocalVarExpr local) { visit(local.init, env); } Using the DeconstructionPattern, i can transform the code to Env env = ... if (expr instanceof LocalVarExpr(var name, var init)) { visit(init, env); } but it also introduce the local variable 'name' in the block Obviously, the way to solve that is to use '_' like this: Env env = ... if (expr instanceof LocalVarExpr(_, var init)) { visit(init, env); } I wonder if introducing only the DeconstructionPattern as Point(int x, int y) and Point(var x, var y) without introducing '_' is a good idea. Declaring a local variable you don't want make the code very artificial. cheers, Rémi ----- Mail original ----- > De: "jan lahoda" <jan.lah...@oracle.com> > À: "amber-dev" <amber-...@openjdk.java.net> > Envoyé: Jeudi 6 Février 2020 21:18:52 > Objet: Pattern Matching for instanceof (Preview 2) > Hi, > > Thanks to Gavin, Brian and Alex, there is a new draft JEP for Pattern > Matching for instanceof (Preview 2): > https://bugs.openjdk.java.net/browse/JDK-8235186 > > Any feedback on the JEP is more than welcome! > > Thanks, > Jan