Enums of Lambdas

Millies, Sebastian Sebastian.Millies at softwareag.com
Thu Oct 3 01:20:46 PDT 2013


no particular reason, just two strategies to do something. – Sebastian

From: Samir Talwar [mailto:samir at noodlesandwich.com]
Sent: Thursday, October 03, 2013 12:31 AM
To: Millies, Sebastian
Cc: lambda-dev at openjdk.java.net
Subject: Re: Enums of Lambdas

// 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<mailto: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