Pattern instanceof Variable JEP clarification
Aaron Scott-Boddendijk
talden at gmail.com
Wed Nov 27 20:57:51 UTC 2019
The pattern of returning early in methods has become very popular and for
us seems to mean that most 'instance of' checks are actually 'not instance
of' checks.
It's times like this I wish we had a '!instanceof' operator for better
readability.
eg `if (e !instanceof String s)` vs `if (!(e instanceof String s))`
That said, instanceof checks are not something we do a lot of (outside of
equals methods).
--
Aaron
On Wed, Nov 27, 2019 at 4:54 AM Brian Goetz <brian.goetz at oracle.com> wrote:
> > Have a few clarifications, assuming we take the following example:
> >
> > public void method foo() {
> >
> >
> > if (e instanceof String s) {
> > // s allowed
> > } else {
> > // s not allowed
> > }
> > // A: s should not be allowed here?
> > }
>
> In this example, s is allowed at A if and only if the ELSE block never
> completes normally. (In that case, in all the cases you could get to A, it
> is because the match succeeded, and hence s would be DA.)
>
>
>
More information about the amber-spec-observers
mailing list