Pair.leftValue() and Pair.rightValue() are too restricted
Issue #52
resolved
I would like to sort a list of pairs, but I could not create an Ordering object:
Ordering<Pair<Integer, String>> ordering = Ordering.natural().onResultOf(Pair.<Integer> leftValue());
I think, Pair.leftValue() should have two parameters (A and B) and return Function<Pair<A, B>, A>, not Function<Pair<A, ?>, A>
Comments (3)
-
-
@orionll is this a 2.x problem? Java 8 solves this with method references.
Ordering<Pair<Integer, String>> ordering = Ordering.natural().onResultOf(Pair::left);
Interestingly the calling code can decide to forget the second type.
Function<Pair<Integer, ?>, Integer> ps = Pair::left;
Off the top of my head I'm not sure what changing leftValue from <A, ?> to <A, B> does to binary compatibility. If the addition does not break binary compatibility feel free to submit a PR against 2.6.x for a pre Java 8 release.
-
- changed status to resolved
timing out
- Log in to comment
Ordering<Pair<Integer, ?>>
is not good enough for your need I presume? That's the problem with variance annotations: when you start using them, then they must spread everywhere...