Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: removed unnecessary arithmeticexception

...

Code Block
bgColor#FFcccc
final class Adder {
  private final AtomicInteger a = new AtomicInteger();
  private final AtomicInteger b = new AtomicInteger();

  public int getSum() throws ArithmeticException {
    return a.get() + b.get(); // or, return a.getAndAdd(b.get());
  }

  public void setValues(int a, int b) {
    this.a.set(a);
    this.b.set(b);
  }
}

...

Code Block
bgColor#ccccff
final class Adder {
  private final AtomicInteger a = new AtomicInteger();
  private final AtomicInteger b = new AtomicInteger();

  public synchronized int getSum() throws ArithmeticException {
    return a.get() + b.get(); // or, return a.getAndAdd(b.get());
  }

  public synchronized void setValues(int a, int b) {
    this.a.set(a);
    this.b.set(b);
  }
}

...