Pattern Matching for instanceof (Preview 2)

Brian Goetz brian.goetz at
Tue Mar 10 12:30:35 UTC 2020

While I understand your concern, I think its a bit of an exaggeration to 
suggest we consider not doing the feature at all if we cannot also 
staple on this other feature.

I'll be brief since all of this has come up before:

  - Yes, we understand that some way to say "don't care about the name" 
is going to eventually be important.

  - I do not want to blindly assume that using underscore as it is in 
other languages is the obvious, or only, or right solution -- in fact, I 
don't think the "obvious" answer is the right solution for Java.

  - I really don't want to distract us with this right now; we have too 
much else on our plate.  Yes, I understand the problem; no, I don't 
agree with the proposed solution; yes, I have other ideas in mind; no, I 
don't want to talk about them now.  We can return to this issue when the 
bigger issues are covered.

On 3/8/2020 10:39 AM, Remi Forax wrote:
> 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.lahoda at>
>> À: "amber-dev" <amber-dev at>
>> 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):
>> Any feedback on the JEP is more than welcome!
>> Thanks,
>>       Jan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the amber-spec-experts mailing list