MoreSuppliers { public static <T> CloseableSupplier<T> lazy(Supplier<T> delegate) { return lazy(delegate, true); }  static CloseableSupplier<T> lazy(Supplier<T> delegate); static CloseableSupplier<T> lazy(Supplier<T> delegate, boolean resetAfterClose); static CloseableThrowableSupplier<T, X> lazyEx(ThrowableSupplier<T, X> delegate); static CloseableThrowableSupplier<T, X> lazyEx(ThrowableSupplier<T, X> delegate,
            boolean resetAfterClose); @Deprecated static Supplier<T> asyncLazy(Supplier<T> delegate, Supplier<T> pendingSupplier,
            String threadName); @Deprecated static Supplier<T> asyncLazy(Supplier<T> delegate, String threadName); @Deprecated static Supplier<T> asyncLazy(Supplier<T> delegate); static AsyncSupplier<T> asyncLazyEx(Supplier<T> delegate, Supplier<T> pendingSupplier,
            String threadName); static AsyncSupplier<T> asyncLazyEx(Supplier<T> delegate, String threadName); static AsyncSupplier<T> asyncLazyEx(Supplier<T> delegate);  }
@Test void test() { int[] counter = { 0 }; CloseableSupplier<String> supplier = lazy(() -> { counter[0]++; return "test"; }); assertEquals(supplier.get(), "test"); assertEquals(counter[0], 1); supplier.tryClose(); assertEquals(supplier.get(), "test"); assertEquals(counter[0], 2); }
@Test void tesNull() { int[] counter = { 0 }; CloseableSupplier<String> supplier = lazy(() -> { counter[0]++; return null; }); assertNull(supplier.get()); assertNull(supplier.get()); assertEquals(counter[0], 1); supplier.tryClose(); assertNull(supplier.get()); assertNull(supplier.get()); assertEquals(counter[0], 2); }