Versions Compared

Key

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

...

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

However, the precedence rules result in the expression to be printed being parsed as ("value=" + s) == null? 0 : 1.

...

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

...