如何将Java静态方法导入Drools文件? [英] How to import Java static method into Drools file?

查看:66
本文介绍了如何将Java静态方法导入Drools文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java 类和静态方法代码为:

The java class and static method code is:

public class DroolsStringUtils {
    public static boolean isEmpty(String param) {
        if (param == null || "".equals(param)) {
            return true;
        }
        return false;
    }
}

drl 代码为:

package com.rules

import com.secbro.drools.utils.DroolsStringUtils.isEmpty;

rule CheckIsEmpty
  when
    isEmpty("");
  then
    System.out.println("the param is not empty");
  end

但是IDEA提示:

无法爱"在方法'isEmpty("))'上.

我只想将静态方法从 java 类导入到 drl 文件.

I just want to import a static method from java class to drl file.

推荐答案

使用import static 导入静态方法.

Use import static to import a static method.

import  static  com.secbro.drools.utils.DroolsStringUtils.isEmpty;
//      ^^^^^^

(已),当然,您不能在需要模式的地方调用静态方法:

(edited:) and of course you cannot call a static method where a pattern is required:

rule CheckIsEmpty
when
    eval( isEmpty("") )
then
    System.out.println("the param is not empty");
end

(阅读Drools文档很有帮助.)

(It helps considerably to read the Drools documentation.)

这篇关于如何将Java静态方法导入Drools文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆