Method reference

 

import java.util.Arrays;
import java.util.function.BiFunction;

/********************************/
@FunctionalInterface
interface MyInterface{
    void display();
}

public class App {

    public void myMethod(){
        System.out.println("Instance Method");
    }

    public static void main(String[] args) {
        App obj = new App();
        MyInterface ref = obj::myMethod;
        ref.display();
    }
}
/********************************/


/********************************/
class Multiplication{
    public static int multiply(int a, int b){
        return a*b;
    }
}

class Example {
    public static void main(String[] args) {
        BiFunction<Integer, Integer, Integer> product = Multiplication::multiply;
        int pr = product.apply(11, 5);
        System.out.println("Product of given number is: " + pr);
    }
}
/********************************/


/********************************/
class Example2 {

    public static void main(String[] args) {
        String[] stringArray = { "Steve", "Rick", "Aditya", "Negan", "Lucy", "Sansa", "Jon"};
        /* Method reference to an instance method of an arbitrary
         * object of a particular type
         */
        Arrays.sort(stringArray, String::compareToIgnoreCase);
        for(String str: stringArray){
            System.out.println(str);
        }
    }
}
/********************************/


/********************************/
interface MyInterface2{
    Hello display(String say);
}
class Hello{
    public Hello(String say){
        System.out.print(say);
    }
}

class Example3 {
    public static void main(String[] args) {
        //Method reference to a constructor
        MyInterface2 ref = Hello::new;
        ref.display("Hello World!");
    }
}
/********************************/
import java.util.function.BiFunction;

public class App{
    public static void main(String[] args) {
        App app = new App();
        app.start();
    }

    public static long multiply(int a, int b) {
        return a*b;
    }

    private void start() {
        BiFunction<Integer, Integer, Long> multi = App::multiply;
        System.out.println(multi.apply(3, 3));
    }
}
output:
9