4 ms·
> 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 th
by _old_dude_ 6y ago
> 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.
- Twisol 6y agoSure. 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); }