繁体   English   中英

什么调用匿名内部类中的方法?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM