...
| Code Block | ||
|---|---|---|
| ||
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 | ||
|---|---|---|
| ||
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
}
}
|
...