Drools导入Java静态方法 [英] Drools imports java static method
本文介绍了Drools导入Java静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
静态Java类和方法代码为:
公共类DroolsStringUtils {
public static boolean isEmpty(String param){
if(param == null || .equals(param)){
返回true;
}
返回false;
}
}
而drl代码是:
package com.rules
import com.secbro.drools.utils .DroolsStringUtils.isEmpty;
规则CheckIsEmpty
当
isEmpty();
然后
System.out.println(参数不为空);
end
但是IDEA暗示方法'isEmpty(
,但是它不起作用!
解决方案
使用import static 导入静态方法。
导入静态com.secbro.drools.utils.DroolsStringUtils.isEmpty;
// ^^^^^^
(编辑:),当然不能调用需要模式的静态方法:
规则CheckIsEmpty
,当
eval(isEmpty( ))
然后
System.out.println(参数不为空);
end
(这有助于阅读Drools文档。)
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!
解决方案
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.)
这篇关于Drools导入Java静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文