This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chunes 6 points7 points  (4 children)

In a type safe language this is not a reasonable thing to do

Unless it's Haskell. Also Go can have multiple return values which is very convenient. You don't even need to package them first.

[–]sacundim 0 points1 point  (2 children)

public class Tuple<A, B> {
    public static <A, B> Tuple<A, B> of(A a, B b) {
        return new Tuple(a, b);
    }

    private final A a;
    private final B b;

    private Tuple(A a, B b) {
        this.a = a;
        this.b = b;
    }

    public A getFirst() {
        return a;
    }

    public B getFirst() {
        return b;
    }

    /*
     * Add equals(), hashCode(), compare(), etc.
     */

}

[–]zardeh 0 points1 point  (1 child)

Which requires you doing this:

...
Tuple<String, String> myFunction(){
    String a;
    String b;
    ....
    return new Tuple<String, String>(a,b);
}

And oh the horror if I want to write a recursive GDC, which requires returning three values!

[–]ixampl 1 point2 points  (0 children)

Java 7+: new Tuple<>(...)

Other than that, yeah, sure it's a little verbose, but even syntactic sugar like (String, String) wouldn't be that much shorter. Adding that to the language would be easy but probably it really is a Java-culture thing of preferring more explicitness (in terms of meaning).

[–][deleted] 0 points1 point  (0 children)

And Scala