@Test public void fn1() { Supplier<String> eval = new LazyEval<>(fn_1, "arg0"); when(fn_1.apply("arg0")).thenReturn("foobar"); assertEquals("1st invocation", "foobar", eval.get()); assertEquals("2nd invocation", "foobar", eval.get()); verify(fn_1, times(1)).apply(any()); verifyNoMoreInteractions(fn_1); verifyZeroInteractions(fn_0, fn_2, fn_3); }
@Override public T get() { if (value_ == null) { synchronized (this) { if (value_ == null) { value_ = actual_.get(); if (value_ != null) actual_ = null; } } } return value_; }
LazyEval implements Supplier<T> { @Override public T get() { if (value_ == null) { synchronized (this) { if (value_ == null) { value_ = actual_.get(); if (value_ != null) actual_ = null; } } } return value_; } }
LazyEval implements Supplier<T> { @Override public T get() { if (value_ == null) { synchronized (this) { if (value_ == null) { value_ = actual_.get(); if (value_ != null) actual_ = null; } } } return value_; } LazyEval(Supplier<? extends T> actual); <X> LazyEval(Function<? super X, ? extends T> fn, X arg); <X, Y> LazyEval(BiFunction<? super X, ? super Y, ? extends T> fn, X x, Y y); <X, Y, Z> LazyEval(TriFunction<? super X, ? super Y, ? super Z, ? extends T> fn, X x, Y y, Z z); }
LazyEval implements Supplier<T> { @Override public T get() { if (value_ == null) { synchronized (this) { if (value_ == null) { value_ = actual_.get(); if (value_ != null) actual_ = null; } } } return value_; } LazyEval(Supplier<? extends T> actual); <X> LazyEval(Function<? super X, ? extends T> fn, X arg); <X, Y> LazyEval(BiFunction<? super X, ? super Y, ? extends T> fn, X x, Y y); <X, Y, Z> LazyEval(TriFunction<? super X, ? super Y, ? super Z, ? extends T> fn, X x, Y y, Z z); static LazyEval<T> byValue(T v); @Override T get(); Optional<T> getIfPresent(); }
LazyEval implements Supplier<T> { @Override public T get() { if (value_ == null) { synchronized (this) { if (value_ == null) { value_ = actual_.get(); if (value_ != null) actual_ = null; } } } return value_; } LazyEval(Supplier<? extends T> actual); <X> LazyEval(Function<? super X, ? extends T> fn, X arg); <X, Y> LazyEval(BiFunction<? super X, ? super Y, ? extends T> fn, X x, Y y); <X, Y, Z> LazyEval(TriFunction<? super X, ? super Y, ? super Z, ? extends T> fn, X x, Y y, Z z); static LazyEval<T> byValue(T v); @Override T get(); Optional<T> getIfPresent();  }