Rémi Forax forax at
Wed Mar 31 07:31:22 UTC 2010

Le 31/03/2010 01:34, joe.darcy at a écrit :
> On 3/30/2010 10:54 AM, Kevin Bourrillion wrote:
>> Pair is only a partial, flawed solution to a special case (n=2) of a 
>> very significant problem: the disproportionate complexity of creating 
>> value types in Java.  I support addressing the underlying problem in 
>> Java 8, and not littering the API with dead-end solutions like Pair.
> While I have sympathy with that conclusion, there is the
> side-effect of littering many APIs with the flotsam of lots of different
> classes named "Pair."  My inclination would be to produce one adequate
> Pair class in the JDK to prevent the proliferation of yet more Pair 
> classes in other code bases.
> I should know better than to take the bait, below is a first cut at
> java.util.Pair.

In equals, instanceof Pair should be instanceof Pair<?,?>.
Pair is a raw type.

getA()/getB should be renamed to getFirst()/getSecond(),
according to their javadoc.

Object.toString() is not necessary in Pair.toString() because
StringBuilder.append (in fact String.valueOf()) already
returns "null" for null.
And minor optimisation, ']' can be used instead of "]".

public String toString() {
     return "[" +a + ", " + b + ']';

> -Joe


More information about the core-libs-dev mailing list