News for hackers. Stuff that matters.
Re:Java’s Cultural Problem by marginalia_nu on Monday September 19, 2022 @12:59PM (#32900922)
> An other thing is java's lack of tuples. All the time I'm reaching for some kind of ad-hoc grouping/touple but have to resort to using something from Apache or Spring or (perhaps abusing) Map.Entry<K,V>

Record types does make that a lot easier. They aren't quite as ad-hoc as in other languages, but this:

  record Foo(int a, String b) {}
is a lot less to type than

  static final class Foo {
    private final int a;
    private final String b;
    public final Foo(int a, String b) {
      this.a = a;
      this.b = b;
    }
    public int a() {
      return a;
    }
    public String b() {
      return b;
    }
    public int hashCode() {
      return Objects.hashCode(a, b);
    }
    public boolean equals(Object o) {
      if (o == null) return false;
      if (o == this) return true;
      if (o instanceof Foo f) {
        return a == f.a && Objects.equals(b, f.b);
      }
      return false;
    }
    public String toString() {
      return getClass().getSimpleName() + "[ a = " + a + ", " + "b = " + b + "]";
    }
  }

There are no comments on this comment yet.