我正在尝试使用由静态嵌套类组成的实用程序类来实现通用功能。这些静态嵌套类正在实现一个命令样式接口:
public interface BooleanFunction{
public boolean execute();
}
持有这些实现此接口的公共类的类是:
public class ExBooleans {
public static class isComponentOpen implements BooleanFunction {
private int widgetId;
private int componentId;
public isComponentOpen(int widgetId, int componentId) {
this.widgetId = widgetId;
this.componentId = componentId;
}
@Override
public boolean execute() {
return Widgets.getComponent(this.widgetId, this.componentId) != null;
}
}
这意味着这样调用:
ExUtilities.makeCondition(new ExBooleans.isComponentOpen(RANGE_WIDGET_ID, RANGE_COOK_COMPONENT_ID), 1000)
哪里makeCondition
接受 a BooleanFunction
:
public static boolean makeCondition (final BooleanFunction booleanFunction, int timeout){
return Utilities.waitFor(new Condition() {
@Override
public boolean validate() {
return booleanFunction.execute();
}
}, timeout);
}
这一切都是为了为Utilities.waitFor(Condition c, int timeout)
函数提供一个包装器,以使代码更清晰、更易读。
但是,当我调用makeCondition
传入时,ExBooleans.isComponentOpen
我收到一个运行时错误:
Unhandled exception in thread ~threadnumber~: java.lang.NoClassDefFoundError: api/ExBooleans$isComponentOpen
在包含来自上面的调用的行:
ExUtilities.makeCondition(new ExBooleans.isComponentOpen(RANGE_WIDGET_ID, RANGE_COOK_COMPONENT_ID), 1000)
任何解决此问题的帮助将不胜感激!