[英]What calls a method inside an anonymous inner class?
在https://gist.github.com/bernii/5697073上的示例程序中
在代码中
this.wait.until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching ...");
return webDriver.findElement(By.id("resultStats")) != null;
}
});
匿名内部类中的apply()方法是怎么调用的?
可能是until
方法,它接收ExpectedCondition<Boolean>
实例。 这是唯一可以调用它的方法(除非until
方法在某个实例变量(或静态变量)中存储对该实例的引用,并且其他一些方法使用该引用在其他时间调用apply
方法)。
匿名内部类类似于本地类,只是它们没有名称。 ExpectedCondition 的子类将在后台创建,它将调用其中的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.