Obiously, an expression like !b instanceof SomeType
(read: "negate b
, then check if the resulting value is of Type SomeType
") doesn't make much sense in Java:
Logically, b
had to be some kind of boolean object (so that !
works) and even if you negated its value, it would still be a boolean value, of the same type as before, so why bother negating it in the first place?
(Actually, you can't even do it: b
can't be a boolean
, because instanceof
requires it to be a real Object
, but then again, if b
is a Boolean
, !b
would still evaluate to a primitive boolean
, so instanceof
doesn't work.)
We can therefore say that !b instanceof SomeType
has no semantic meaning in Java at all. So we could reassign its meaning to "check if b
is not of type SomeType
" - can't we?
Given that this could've been changed semantically and still wasn't done leaves me with the conclusion that this was not really intentional, but there was a more pragmatic reason to go with the lower precedence for instanceof
:
Off the top of my head, I would suspect that parsing gets complicated if you give instanceof
higher precedence than the unary operator !
. You might want to check that.
On the other hand, if !b instanceof SomeType
would mean "check if b
is not of type SomeType
", this could still trick novice programmers into thinking that !
operates on b
when in fact it negates the result of instanceof
, so it's less ambiguous to leave !b instanceof SomeType
essentially undefined.