News for hackers. Stuff that matters.
Re:The visitor pattern is essentially the same thing as Chur... by _old_dude_ on Thursday February 04, 2021 @07:00AM (#26024626)
> The downside is that Java doesn't let you implement generic methods with lambdas ...

yes, that exactly why i've chosen to make the type parametric and not the method apply, but you're right that the classical visitor pattern uses a polymorphic method (accept) not a polymorphic class.

Re:The visitor pattern is essentially the same thing as Chur... by Twisol on Thursday February 04, 2021 @07:02AM (#26024638)
Sure. Then, if you're set on using lambdas, I'd recommend this, to at least take away the ability to choose <T> from the caller.

    static Shape<?> Circle(int x, int y, int r) {
      return (circle, rectangle) -> circle.apply(x, y, r);
    }
    static Shape<?> Rectangle(int x, int y, int w, int h) {
      return (circle, rectangle) -> rectangle.apply(x, y, w, h);
    }