/** * Creates a {@code Lazy} that requests its value from a given {@code Supplier}. The supplier is asked only once, * the value is memoized. * * @param <T> type of the lazy value * @param supplier A supplier * @return A new instance of Lazy */ @SuppressWarnings("unchecked") public static <T> Lazy<T> of(Supplier<? extends T> supplier) { Objects.requireNonNull(supplier, "supplier is null"); if (supplier instanceof Lazy) { return (Lazy<T>) supplier; } else { return new Lazy<>(supplier); } }
/** * Creates a {@code Lazy} that requests its value from a given {@code Supplier}. The supplier is asked only once, * the value is memoized. * * @param <T> type of the lazy value * @param supplier A supplier * @return A new instance of Lazy */ @SuppressWarnings("unchecked") public static <T> Lazy<T> of(Supplier<? extends T> supplier) { Objects.requireNonNull(supplier, "supplier is null"); if (supplier instanceof Lazy) { return (Lazy<T>) supplier; } else { return new Lazy<>(supplier); } }