External argument to method reference in Java 8
问题 I am looking to pass an external parameter to a method reference: String prefix = "The number is :"; numbers.forEach(Main::printWithPrefix); private static void printWithPrefix(Integer number) { System.out.println(number); } I am no idea on how to do it. I am able to do it with a lambda: String prefix = "The number is :"; numbers.forEach(number -> { System.out.println(prefix + number); }); Is it possible to pass an external parameter to a method reference? 回答1: No, you cannot pass a parameter