@Test void tryGetFailure() { Lazy<String> sut = new Lazy<>(() -> { throw new RuntimeException("Epic fail."); }); Try<String> result = sut.tryGet(); assertThat(result, is(Try.failure(new RuntimeException("Epic fail.")))); }
public Try<T> tryGet() { Try<T> result = value; if (result == null) { synchronized (lock) { result = value; if (result == null) { value = result = Try.trySupply(supplier); } } } return result; }
Lazy { public Try<T> tryGet() { Try<T> result = value; if (result == null) { synchronized (lock) { result = value; if (result == null) { value = result = Try.trySupply(supplier); } } } return result; } }
Lazy { public Try<T> tryGet() { Try<T> result = value; if (result == null) { synchronized (lock) { result = value; if (result == null) { value = result = Try.trySupply(supplier); } } } return result; } <E extends Exception> Lazy(ThrowingSupplier<T,E> supplier); }
Lazy { public Try<T> tryGet() { Try<T> result = value; if (result == null) { synchronized (lock) { result = value; if (result == null) { value = result = Try.trySupply(supplier); } } } return result; } <E extends Exception> Lazy(ThrowingSupplier<T,E> supplier); Try<T> tryGet(); T get(); Optional<T> optional(); Stream<T> stream(); boolean isKnown(); boolean isKnownSuccess(); boolean isKnownFailure(); Lazy<U> map(ThrowingFunction<? super T, ? extends U, E> function); Lazy<U> flatMap(ThrowingFunction<? super T, Lazy<U>, E> function); }
Lazy { public Try<T> tryGet() { Try<T> result = value; if (result == null) { synchronized (lock) { result = value; if (result == null) { value = result = Try.trySupply(supplier); } } } return result; } <E extends Exception> Lazy(ThrowingSupplier<T,E> supplier); Try<T> tryGet(); T get(); Optional<T> optional(); Stream<T> stream(); boolean isKnown(); boolean isKnownSuccess(); boolean isKnownFailure(); Lazy<U> map(ThrowingFunction<? super T, ? extends U, E> function); Lazy<U> flatMap(ThrowingFunction<? super T, Lazy<U>, E> function);  }