org.rx.core.Lazy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rxlib Show documentation
Show all versions of rxlib Show documentation
A set of utilities for Java
package org.rx.core;
import lombok.RequiredArgsConstructor;
import java.util.function.Supplier;
@RequiredArgsConstructor
public final class Lazy {
private T value;
private final Supplier supplier;
public boolean isValueCreated() {
return value != null;
}
public T getValue() {
if (value == null) {
synchronized (supplier) {
if (value == null) {
value = supplier.get();
}
}
}
return value;
}
}