I want to pass a function as an argument to another function inside another class to execute it and return its return value. Following sample code shows what I want to do. Can you please help me how can I achieve this?
MyClass myClass = new MyClass();
myClass.myFunction( executeFunction( "name", 123 ) );
public long executeFunction( String a, Integer b ) {
//do something
return 321;
}
/* inside MyClass */
public <RetTyp> myFunction( /*accept any function as a parameter with RetTyp as a return data type*/) {
/*execute method coming in the argument and return its return value*/
}