fork download
  1. import java.util.function.Supplier;
  2.  
  3. public enum Main {;
  4.  
  5. public static void main(String[] args) {}
  6.  
  7. public class Lazy<T> {
  8.  
  9. private volatile boolean initialized = false;
  10.  
  11. private T value;
  12.  
  13. private final Supplier<T> supplier;
  14.  
  15. public Lazy(Supplier<T> supplier) {
  16. this.supplier = supplier;
  17. }
  18.  
  19. public T get() {
  20. if (!initialized) {
  21. synchronized (this) {
  22. if (!initialized) {
  23. T localValue = supplier.get();
  24. value = localValue;
  25. initialized = true;
  26. return localValue;
  27. }
  28. }
  29. }
  30. return value;
  31. }
  32.  
  33. }
  34.  
  35. }
Success #stdin #stdout 0.06s 32476KB
stdin
Standard input is empty
stdout
Standard output is empty