Class MethodReferenceExample

java.lang.Object
modernfeatures.methodreferences.MethodReferenceExample

public class MethodReferenceExample extends Object
Demonstrates the use of method references in Java, and contrasts them with lambda expressions. Method references provide a concise way to refer to an existing method, making code more readable.
  • Constructor Details

    • MethodReferenceExample

      public MethodReferenceExample()
  • Method Details

    • main

      public static void main(String[] args)
      Main method demonstrates printing each name in a list using both a lambda expression and various types of method references. The output is identical, but the method reference syntax is more concise.
      Parameters:
      args - Command-line arguments (not used)
    • printUpper

      public static void printUpper(String stringName)
    • printLower

      public void printLower(String stringName)