Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

重写NOT函数出错。 #655

Open
hackerpayne opened this issue Dec 18, 2024 · 0 comments
Open

重写NOT函数出错。 #655

hackerpayne opened this issue Dec 18, 2024 · 0 comments

Comments

@hackerpayne
Copy link

想重写!方法,支持not和!同时使用。

参考一些案例写出来了OR、And方法,是可以用的。

最后可以在表达式里面直接写语法:

true and false;
true or false;
not true;

但是not函数却不行了

/**
 * 处理!和 not
 */
public class NotFunction extends AbstractFunction {

    @Override
    public String getName() {
        return "not";
    }

    @Override
    @SuppressWarnings("all")
    public AviatorObject call(Map<String, Object> env, AviatorObject arg1) {
        Boolean left =  FunctionUtils.getBooleanValue(arg1, env);
        return AviatorBoolean.valueOf(!left);
    }
}

执行时加上:

AviatorEvaluator.getInstance().aliasOperator(OperatorType.NOT, "not");
AviatorEvaluator.addOpFunction(OperatorType.NOT, new NotFunction());

最后报了错误:
Caused by: java.lang.IllegalArgumentException
at com.googlecode.aviator.AviatorEvaluatorInstance.aliasOperator(AviatorEvaluatorInstance.java:235)

求解。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant