Drools imports java static method

丶灬走出姿态 提交于 2019-12-13 00:33:41

问题


The static java class and method code is:

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

}

and the drl code is :

package com.rules

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


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

But the IDEA hints "cannot relove" on the method 'isEmpty("")'.I just want to import a static method from java class to drl file.

but it does not work!


回答1:


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

(It helps considerably to read the Drools documentation.)



来源:https://stackoverflow.com/questions/45072844/drools-imports-java-static-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!