if (!(x instanceof String y)) syntax - better syntax?
Brian Goetz
brian.goetz at oracle.com
Sat Feb 15 19:13:50 UTC 2020
> I can try to contribute a patch for either form. I assume supporting both
> is not desired? I'm honestly not sure which version I prefer. I guess I
> prefer !instanceof but that is a very light precedence and I've clearly
> arrived at the bikeshed painting phase of syntax debate here.
>
> if (!x instanceof String) {}
>
> or
>
> if (x !instanceof String) {}
>
>
The latter form is far preferable; with the prefix notation, there is an
ambiguity of how much the unary operator "eats", whereas in the latter,
`!instanceof` just becomes a new binary operator.
All that said, while perfectly defensible, it is not clear whether it is
justified as an alternative to !(x instanceof P). So let's leave it on
the shelf for a while and see how we feel about it after we can see how
much of an issue it is in real code?
More information about the amber-dev
mailing list