title: Lambdas in the classical Operation enum example
body: <p>As many of you may know, there is a classical example of the <code>Operation</code> enum (using Java 8 standard interface now though), that is the following:</p>
  
  <pre><code>enum Operation implements DoubleBinaryOperator {
      PLUS("+") {
          @Override
          public double applyAsDouble(final double left, final double right) {
              return left + right;
          }
      },
      MINUS("-") {
          @Override
          public double applyAsDouble(final double left, final double right) {
              return left - right;
          }
      },
      MULTIPLY("*") {
          @Override
          public double applyAsDouble(final double left, final double right) {
              return left * right;
          }
      },
      DIVIDE("/") {
          @Override
          public double applyAsDouble(final double left, final double right) {
              return left / right;
          }
      };
  
      private final String symbol;
  
      private Operation(final String symbol) {
          this.symbol = symbol;
      }
  
      public String getSymbol() {
          return symbol;
      }
  }
  </code></pre>
  
  <p>Tested with:</p>
  
  <pre><code>Arrays.stream(Operation.values())
          .forEach(op -&gt; System.out.println("Performing operation " + op.getSymbol() + " on 2 and 4: " + op.applyAsDouble(2, 4)));
  </code></pre>
  
  <p>It provides:</p>
  
  <blockquote>
    <p>Performing operation + on 2 and 4: 6.0<br>
    Performing operation - on 2 and 4: -2.0<br>
    Performing operation * on 2 and 4: 8.0<br>
    Performing operation / on 2 and 4: 0.5  </p>
  </blockquote>
  
  <p>But I feel like we can do better with Java 8, hence I implemented the following:</p>
  
  <pre><code>enum Operation implements DoubleBinaryOperator {
      PLUS    ("+", (l, r) -&gt; l + r),
      MINUS   ("-", (l, r) -&gt; l - r),
      MULTIPLY("*", (l, r) -&gt; l * r),
      DIVIDE  ("/", (l, r) -&gt; l / r);
  
      private final String symbol;
      private final DoubleBinaryOperator binaryOperator;
  
      private Operation(final String symbol, final DoubleBinaryOperator binaryOperator) {
          this.symbol = symbol;
          this.binaryOperator = binaryOperator;
      }
  
      public String getSymbol() {
          return symbol;
      }
  
      @Override
      public double applyAsDouble(final double left, final double right) {
          return binaryOperator.applyAsDouble(left, right);
      }
  }
  </code></pre>
  
  <p>Functionally it is equivalent, however are both implementations still similar, or are there some hidden details that make the new version worse as the old version?</p>
  
  <p>And lastly, is the lambda way the preferred way to do it as of Java 8?</p>