What is the equivalent of Kotlin "by lazy" in Java?
You can call Kotlin lazy
from Java if you want to:
import kotlin.Lazy;
Lazy<SampleLifecycleListener> lazyListener = kotlin.LazyKt.lazy(() -> new SampleLifecycleListener()));
SampleLifecycleListener realListener = lazyListener.getValue();
private SampleLifecycleListener sll;
public synchronized SampleLifecycleListener getSampleLifecycleListener() {
if (sll == null) {
sll = new SampleLifecycleListener();
}
return sll;
}
That way it isn't initialized until the getter is called.