Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: compilation fix

...

Code Block
bgColor#ccccff
public final class Helper {
  private final int n;

  public Helper(int n) {
    this.n = n;
  }

  // Other fields and methods, all fields are final
}

final class Foo {
  private Helper helper = null;
  
  public Helper getHelper() { 
    if (helper == null) {
      synchronized (this) {
        if (helper == null) {
          helper = new Helper(42); // If the helper is null, create a new instance
        }
      }
    }
    return helper; // If helper is non-null, return its instance
  }
}

...