Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Fixed compliant solution – it was wrong

...

Code Block
bgColor#ccccff
class Foo {
  private volatile boolean flag = true;
 
  public synchronized void toggle() { 
    flag ^= true; // same as flag = !flag; 
  }

  public synchronized boolean getFlag() { 
    return flag;
  }
}

...