我正在尝试使用由静态嵌套类组成的Utility类来实现常用功能。这些静态嵌套类正在实现命令样式接口:
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
接受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)
非常感谢任何解决此问题的帮助!
答案 0 :(得分:0)
我能够通过将interface
和makeCondition
方法拉入一个单独的类来解决问题,该类同时包含这些和实用程序实现isComponentOpen
等。这些都嵌套在一个类我不再得到错误,代码可能更有意义组合在一起。
我仍然不确定错误来自哪里。