News for hackers. Stuff that matters.
Re:Java’s Cultural Problem by bluejekyll on Monday September 19, 2022 @06:51AM (#32896638)
My issue with lambdas in Java is the complexity of types in defining interfaces that receive generic Functions as an argument. Really seems like a better definition could be used there, new language syntax possibly.

On the topic of Streams, the big issue that always crops up is exceptions. Streams and Exceptions are nearly incompatible with tacked on constructs that are painful to use. Any IO oriented program will have to face the issue of what happens to the Stream if an Exception is thrown.

Re:Java’s Cultural Problem by joshlemer on Monday September 19, 2022 @12:43PM (#32900698)
Agreed. If the type of the lambda can be inferred, then they are great to work with. But if you want to define one upfront and use it later, having to spell out the type of it is almost prohibitively annoying (what do I need in this situation, is it a Function or a Consumer or Supplier or Bifunction or BiConsumer or BinaryOperator or Predicate or BiPredicate or IntUnaryOperator or ObjDoubleConsumer or LongToDoubleFunction or .........). Most of the time I'll just avoid it if I can. I think I"m the only one on my team who would ever create a local function rather than a private method, for instance.

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>

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 + "]";
    }
  }