Wiki Markup |
---|
Programmers frequently make errors regarding the precedence of operators duebecause toof the unintuitive low-precedence levels of {{&}}, {{\|}}, {{\^}}, {{<<}}, and {{>>}}. Avoid mistakes regarding precedence through the suitable use of parentheses. This also improves code readability, unless taken to excess. The precedence of operations by the order of the subclauses are defined in the Java Tutorials \[[Tutorials 2008|AA. Bibliography#Tutorials 08]\]. |
...
The intent of the expression in this noncompliant code example is to add the variable OFFSET
to the result of the bitwise logical AND between x
and MASK
.
Code Block | ||
---|---|---|
| ||
public static final int MASK = 1337; public static final int OFFSET = -1337; public static int computeCode(int x) { return x & MASK + OFFSET; } |
...
Note that this solution performs bitwise operations on signed integers. Care must be exercised when doing this; see INT06-J. Avoid incorrect mixing of signed integers with bitwise operators for more information.
Exceptions
EXP00-EX1EX0: Parentheses may be omitted from mathematical expressions that follow conventional algebraic orderfollows the algebraic precedence rules. For instance, consider the expression:
...