187. Exemplifying a method reference vs. a lamda
Have you ever written a lambda expression and your IDE advises you to replace it with a method reference? You probably have! And I’m sure that you preferred to follow the replacement because names matter, and method references are often more readable than lambdas. While this is a subjective matter, I’m pretty sure you’ll agree that extracting long lambdas in methods and using/reusing them via method references is a generally accepted good practice.
However, beyond some esoteric JVM internal representations, do they behave the same? Is there any difference between a lambda and a method reference that may affect how the code behaves?
Well, let’s assume that we have the following simple class:
public class Printer {
Printer() {
System.out.println("Reset printer ...");
}
public static void printNoReset() {
System.out.println(
"Printing (no reset...