1public class Main {
2 public static void main(String args[]) {
3 SayHi();
4
5 int sum = AddNums(5, 6);
6 System.out.println(sum);
7 }
8
9 public static void SayHi() { //This method has no return value
10 System.out.println("Hi!");
11 }
12
13 public static int AddNums(int a, int b) { //This method has a return value
14 return a + b;
15}
1Java provides a feature called method
2reference in Java 8. Method reference
3is used to refer method of functional interface.
4 It is compact and easy form
5 of lambda expression. Each time when
6 you are using lambda expression to just
7 referring a method, you can replace your
8 lambda expression with method reference.
9
10Types of Method References:
11- Reference to a static method. Syntax ==> ContainingClass::staticMethodName
12- Reference to an instance method. Syntax ==> containingObject::instanceMethodName
13- Reference to a constructor. Syntax ==> ClassName::new