Figured out something bizarre about combining lambdas just the other day.

Code like

static <R> EqualsSupport<R> makeEquals(Set<Getter<R, ?>> getters) {
   EqualsSupport<O> equals = (a, b) -> true;
   for (var getter : getters) {
      if (getter instanceof ObjectGetter) {
         var g = (ObjectGetter<R, ?>) getter;
         var oldEquals = equals;
         equals = (a, b) -> oldEquals.apply(a, b) && Object.equals(g.get(a), 
g.get(b)));
      } else if (getter instanceof IntGetter) {
         var g = (IntGetter<R>) getter;
         var oldEquals = equals;
         equals = (a, b) -> oldEquals.apply(a, b) && g.get(a) == g.get(b));
      }  else {
         // etc...
      }
   }
   return equals;
}

just doesn't work because the VM thinks it is recursive (it is the same 
method on the lambda just not the same lambda).

So what you need to is use MethodHandles combinators to patch the lambdas 
together. Oddly, for a sequence of lambdas I've found the loop one works 
well.

-- 
You received this message because you are subscribed to the Google Groups 
"mechanical-sympathy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to mechanical-sympathy+unsubscr...@googlegroups.com.
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/mechanical-sympathy/ec9120ca-f3b7-4c9d-90ef-4dacf2e5f810%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to