You need either an interface, or an abstract class to do this. An interface (out of the two) is the better choice in this case.
If a class implements an interface, then it must have the functions listed in the interface. Therefore, when you accept an interface in your function, you know that the object has the function listed (and you can call it).
You will define an interface like so:
public interface Test {
public boolean passedTest();
}
Then you will define classes that implement Test:
public EqualsTest implements Test {
private Foo A, B;
public EqualsTest(Foo A, Foo B){
this.A = A;
this.B = B;
}
@Overrides
public boolean passedTest(){
return A.equals(B);
}
}
Then your function will look like the following:
public waitUntil(Test test){
try{
wait.until(new Function<WebDriver, Boolean>() {
public Boolean apply(WebDriver driver) {
return test.passedTest()
}
}
} catch( Exception ex){
return false;
}
return true;
}