JexlEngine 构造函数不工作? (不能应用于给定类型)

JexlEngine constructor not working? (cannot be applied to given types)

我正在尝试初始化一个 JexlEngine 对象,但构造函数不允许我这样做(尽管文档说明应该这样做)。

这是 JexlEngine class(在 jexl3 中)的文档: https://people.apache.org/~henrib/jexl-3.0/apidocs/org/apache/commons/jexl3/JexlEngine.html

最初代码使用 jexl2 导入,但我最近将项目转换为 Maven,不得不换成 jexl3。现在构造函数不再起作用。

我错过了什么吗?

我运行在 Java 1.8 上在 Netbeans 中 运行 宁这个项目 - 这是一个包含 jexl3 依赖项的 Maven 项目(但是用于与 jexl2 一起工作)

我的代码:

public static final JexlEngine jexl = new JexlEngine(null, new MyArithmetic(), null, null){};

static {
        jexl.setCache(512);
        jexl.setLenient(false); // null shouldnt be treated as 0
        jexl.setSilent(false);  // Instead of logging throw an exception
        jexl.setStrict(true);
}

根据文档,应该有一个带有 4 个参数的构造函数,因为我正在尝试 运行 它,但由于某些奇怪的原因,它不会让我 运行 它。任何想法为什么? (再次 - 它曾经与 Jexl2 一起工作)

错误日志:

Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project bilbon-core: Compilation failure: Compilation failure:
si/smth/project/bean/CUtil.java:[333,43] constructor JexlEngine in class org.apache.commons.jexl3.JexlEngine cannot be applied to given types;
required: no arguments
found: <nulltype>,si.smth.project.bean.CUtil.MyArithmetic,<nulltype>,<nulltype>
reason: actual and formal argument lists differ in length
si/smth/project/bean/CUtil.java:[333,99] <anonymous si.smth.project.bean.CUtil> is not abstract and does not override abstract method newInstance(java.lang.String,java.lang.Object...) in org.apache.commons.jexl3.JexlEngine
si/smth/project/bean/CUtil.java:[336,13] cannot find symbol
symbol:   method setCache(int)
location: variable jexl of type org.apache.commons.jexl3.JexlEngine
si/smth/project/bean/CUtil.java:[337,13] cannot find symbol

使用空构造函数,这是latest java docs

中唯一的构造函数
JexlEngine jexl = new JexlEngine();

或使用 JexlBuilder,如 jexl 中所述:

JexlEngine jexl = new JexlBuilder().create();

您可以为您的 setter 调用构建器方法:

JexlEngine jexl = strict(true).silent(false).cache(512) .create();

你有 setSilentsetStrict 组合而不是宽松标志:

The setSilent and setStrict methods allow to fine-tune an engine instance behavior according to various error control needs. The strict flag tells the engine when and if null as operand is considered an error, the silent flag tells the engine what to do with the error (log as warning or throw exception).

  • When "silent" & "not-strict": 0 & null should be indicators of "default" values so that even in an case of error, something meaningful can still be inferred; may be convenient for configurations.
  • When "silent" & "strict": One should probably consider using null as an error case - ie, every object manipulated by JEXL should be valued; the ternary operator, especially the '?:' form can be used to workaround exceptional cases. Use case could be configuration with no implicit values or defaults.