How to get information about FunctionalInterface method in java 8 lambda

I want to check if two lambda methods are equal; For example:

public class App {

    @FunctionalInterface
    public interface TestFunctionInterface {
        void get();
    }

    public static void main(String[] args) throws Throwable {
        TestFunctionInterface t1 = App::print1;
        TestFunctionInterface t2 = App::print1;
        TestFunctionInterface t3 = App::print2;
        System.out.println(t1.equals(t2));
        System.out.println(!t1.equals(t3));
    }

    private static void print1() {
    }

    private static void print2() {
    }
}

      

output:

false

true

      


My goal is to check that two lambda functions are the same method.

i.e. with a test that returns true.

This way, can I get information about the method with FunctionalInterface?

thank

+3


source to share





All Articles