Method Reference
- Method reference is a shorthand syntax for a Lambda Expression In Java that contains just 1 method call. We are passing a function and not invoking a fucntion hence
Object::method name
When to use ? Receiving an argument or parameter and you want NOT ALTER IT in anyway but let it PASS through.Use it as gluecode .
When NOT to use? If we want to perform operations on it then NOT usefule
public class Sample {
public static void main(String[] args) {
List<Integer> numbers= Arrays.asList(1,2,3,4,5,6,7,8,9,10);
System.out.println("Method refernce ");
// We are passing a function and not invoking a fucntion hence ::
//Method Reference
numbers.forEach(System.out::println);
}}