No, they are not equivalent. Eliminate this a bit, so it’s clearer - let's just use 2 examples and make them x and y instead of “matcherX.matches ()”. In this case, you ask:
Are these two equivalents?
if (!x && !y) { return true; } else return false;
and
return (x || y);
Free your way. First, the original operator can be explicitly converted directly to
return (!x && !y);
Here's the truth table for this:
| x | y | !x && !y | +---------+---------+------------+ | T | T | F | | T | F | F | | F | T | F | | F | F | T |
That is, the first expression returns true only when none of the subexpressions is true. Same as
return !(x || y);
source share