Enums of Lambdas

Samir Talwar samir at noodlesandwich.com
Wed Oct 2 15:31:14 PDT 2013


// Sending again, because "Reply" doesn't reply to the list.

Why does CalcAdd do slow multiplication?

— Samir.


On Wed, Oct 2, 2013 at 7:59 PM, Millies, Sebastian <
Sebastian.Millies at softwareag.com> wrote:

> Hi there,
>
> what's the most elegant way to define an enum of lambdas?
> For example, this enum of BinaryOperators looks clumsy:
>
> public static enum Calc {
>
>         CalcMult((n, m) -> n * m),
>
>         CalcAdd((n, m) -> {
>             int result = 0;
>             for (int i = 0; i < n; i++)
>                 result += m;
>             return result;
>         });
>
>         private Calc(IntBinaryOperator op) {
>             this.op = op;
>         }
>
>         private final IntBinaryOperator op;
>     }
>
> I guess I'd perhaps be better off not using an enum at all, but just two
> static final members.
>
>
> n  Sebastian
>
>
>
> Software AG - Sitz/Registered office: Uhlandstra?e 12, 64297 Darmstadt,
> Germany - Registergericht/Commercial register: Darmstadt HRB 1562 -
> Vorstand/Management Board: Karl-Heinz Streibich (Vorsitzender/Chairman),
> Dr. Wolfram Jost, Arnd Zinnhardt; - Aufsichtsratsvorsitzender/Chairman of
> the Supervisory Board: Dr. Andreas Bereczky - http://www.softwareag.com
>
>
>


More information about the lambda-dev mailing list