Pair { public static <T1, T2> Function<Pair<T1, T2>, T1> lhsFn() { return new Function<Pair<T1, T2>, T1>() { @Override public T1 apply(Pair<T1, T2> input) { return input.lhs; } }; } Pair(T1 lhs, T2 rhs); static Pair<T1, T2> of(T1 lhs, T2 rhs); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static Function<Pair<T1, T2>, T1> lhsFn(); static Function<Pair<T1, T2>, T2> rhsFn(); static Comparator<Pair<T1, ?>> lhsComparator(final Comparator<T1> comparator); final T1 lhs; final T2 rhs; }
@Test public void testLhsFn() { Pair pair = new Pair("lhs", "rhs"); Assert.assertEquals("foo", pair.lhsFn().apply(new Pair<>("foo", "bar"))); }