Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
x & (MASK + OFFSET)

This expression gets is evaluated as follows, resulting in the value 0:

...

This compliant solution uses parentheses to ensure that the expression evaluates is evaluated as intended:

Code Block
bgColor#ccccff
public static final int MASK = 1337;
public static final int OFFSET = -1337;

public static int computeCode(int x) {
  return (x & MASK) + OFFSET;
}

...

In this noncompliant code example, the intent is to add append either "0" or "1" to the string "value=":

Code Block
bgColor#FFCCCC
public class Test{
    public static void main(String[] args) {
        String s = null;
        System.out.println("value=" + s == null? 0 : 1); // prints "1"
    }
}

...