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
java lambda java-8 functional-interface method-reference


source to share


No one has answered this question yet

See similar questions:

61
Is there a way to compare lambda?
49
How to get MethodInfo of Java 8 method references?
nine
Printing debug error information with java 8 lambda expressions
nine
Is it possible to convert a method reference to a MethodHandle?

or similar:

6170
Is Java "pass-by-reference" or "pass-by-value"?
3799
How do I read / convert an InputStream to a string in Java?
3324
How to generate random integers in a specific range in Java?
3073
How to efficiently iterate over each entry in a Java map?
2936
When to use LinkedList over ArrayList in Java?
2853
How can I convert String to int in Java?
2248
Is a finally block always executable in Java?
2171
How to determine if an array contains a specific value in Java?
2108
How can I call one constructor from another in Java?
1818
How to get enum value from string value in Java?



All Articles
Loading...
X
Show
Funny
Dev
Pics