Lambdas only for simple cases

Objects that implement functional interfaces can be made in 3 ways:

If the method already exists, then a method reference should always be preferred over a lambda. In addition, method references are usually preferred when one or more of these conditions apply:

Lambdas work best when the method doesn't currently exist, and all of these conditions apply:

In short, lambdas work best only in simpler cases.


import java.util.Optional;

/** @since Java 8 */
public final class LambdaForSimpleCases {
  public static void main(String... args) {
    LambdaForSimpleCases atoms = new LambdaForSimpleCases();

   Find the lightest element that's always unstable.
  void findLightestUnstableElement(){
    Optional<Atom> answer = Stream.of(Atom.values())
      //this method exists, so just use a method reference; don't use a lambda 
      //using a lambda; not very complex, and the method doesn't already exist
      .max((a,b) -> b.numProtons.compareTo(a.numProtons))  
    answer.ifPresent(atom -> log("Lightest unstable element:", " " + atom.getName()));
   Some data from the periodic table of the elements (incomplete!). 
  enum Atom {
    H("Hydrogen", 1, false),
    Tc("Technetium", 43, true),
    Au("Gold", 79, false),
    Pb("Lead", 82, false),
    Pu("Plutonium", 94, true),
    Fm("Fermium", 100, true);
    private Atom(String name, Integer numProtons, Boolean isAlwaysUnstable){ = name;
      this.numProtons = numProtons;
      this.isAlwaysUnstable = isAlwaysUnstable;
    Boolean isAlwaysUnstable() { return isAlwaysUnstable; }
    String getName() { return name;  }
    Integer getNumProtons() { return numProtons; }
    private String name;
    private Integer numProtons;
    private Boolean isAlwaysUnstable;
  private static void log(Object... msgs){