Versions Compared

Key

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

...

Code Block
bgColor#FFCCCC
public class ShortSet {
  public static void main(String[] args) {
    HashSet<Short> s = new HashSet<Short>();
    for (short i = 0; i < 100; i++) {
      s.add(i);
      // Cast of i-1 is safe, because value is always representable
      Short workingVal = (short) (i-1);
      // ... // other code may update workingVal

      s.remove(((i % 2) == 1) ? i-1 : workingVal);
    }
    System.out.println(s.size());
  }
}

...

Code Block
bgColor#ccccff
public class ShortSet {
  public static void main(String[] args) {
    HashSet<Short> s = new HashSet<Short>();
    for (short i = 0; i < 100; i++) {
      s.add(i);
      // Cast of i-1 is safe, because value is always representable
      Short workingVal = (short) (i-1);
      // ... // other code may update workingVal

      // Cast of i-1 is safe, because value is always representable
      s.remove(((i % 2) == 1) ? Short.valueOf((short) (i-1)) : workingVal);
    }
    System.out.println(s.size());
  }
}

...