WeakLogic { public static <F, T> Function<F, T> weakFunction(Function<F, T> f) { return x -> x == null ? null : f.apply(x); } private  WeakLogic(); static Comparator<T> weakComparator(Comparator<? super T> comparator); static Comparator<T> weakComparator(); static BinaryOperator<T> weakBinaryOperator(BinaryOperator<T> op); static UnaryOperator<T> weakUnaryOperator(UnaryOperator<T> op); static Function<F, T> weakFunction(Function<F, T> f); static boolean weakEquals(T x, T y);  }
@Test public void testWeakFunction() { Function<Integer, Integer> weak2 = weakFunction(x -> 2 * x); int s = weak2.apply(5); assertEquals(10, s); assertNull(weak2.apply(null)); }