Skip to content

Commit

Permalink
Improve OperatorPrecedence docs
Browse files Browse the repository at this point in the history
#4153

PiperOrigin-RevId: 574878098
  • Loading branch information
cushon authored and Error Prone Team committed Oct 19, 2023
1 parent 31cc82f commit 3f45547
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions docs/bugpattern/OperatorPrecedence.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,21 @@ The [Google Java Style Guide §4.7][style] states:
[style]: https://google.github.io/styleguide/javaguide.html#s4.7-grouping-parentheses

Use grouping parentheses to disambiguate expressions that contain both `||` and
`&&`, or both shift and arithmetic operators.
Use grouping parentheses to disambiguate expressions that could be
misinterpreted.

For example, consider this:

```java
boolean d = (a && b) || c;",
boolean e = (a || b) ? c : d;",
int z = (x + y) << 2;",
```
Instead of this:
```java
boolean r = a && b || c;",
boolean e = a || b ? c : d;",
int z = x + y << 2;",
```

0 comments on commit 3f45547

Please sign in to comment.