Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
public class Expr {
  public static void main(String[] args) {
    char alpha = 'A';
    int i = 0;
    /* Other code. Value of i may change */
    boolean trueExp = ...; // someSome expression that evaluates to true
    System.out.print(trueExp ? alpha : 0); // prints A
    System.out.print(trueExp ? alpha : i); // prints 65
  }
}

...

Code Block
bgColor#ccccff
public class Expr {
  public static void main(String[] args) {
    char alpha = 'A';
    int i = 0;
    boolean trueExp = ...; // someSome expression that evaluates to true
    System.out.print(trueExp ? alpha : ((char) 0)); // prints A
    // Deliberate narrowing cast of i; possible truncation OK
    System.out.print(trueExp ? alpha : ((char) i)); // prints A
  }
}

...