I have a functional interface and a class using that interface not I would like to have the name of the method of the class and not that of the interface . The code given below :
@FunctionalInterface
interface MyInterface{
void display();
}
public class Example {
public static void myMethod(){
System.out.println("Instance Method");
System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());
}
public static void myMethod1(){
System.out.println("Instance Method");
System.out.println(new Object(){}.getClass().getEnclosingMethod().getName());
}
public static String myMethod2(){
return "exec";
}
public static void main(String[] args) throws NoSuchMethodException, SecurityException, ClassNotFoundException {
// Method reference using the object of the class
MyInterface ref = Example::myMethod2;
// Calling the method of functional interface
}
}
So the output required should be the method name of the class i.e
myMethod2
provided this method should not execute and nothing should be change