Drools中的“无法找到课程"错误 [英] `Unable to find class` error in Drools
本文介绍了Drools中的“无法找到课程"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Drools
中定义一个非常简单的函数,如下所示:
I'm trying to define a very simple function in Drools
as below:
import java.util.List;
function int sumLengths(List<String> strings) {
int counter = 0;
for (String s : strings)
counter += s.length();
return counter;
}
但它给了我错误:
Exception in thread "main" java.lang.RuntimeException: [ function sumLengths (line:5):
Unable to resolve type List<String> while building function. java.lang.ClassNotFoundException: Unable to find class 'List<String>' ]
有什么主意吗?
推荐答案
Perhaps it is an issue with generics (This points me to that conclusion). Have you tried the following (or similar):
function int sumLengths(List strings) {
int counter = 0;
for (Object s : strings)
counter += ((String) s).length();
return counter;
}
如果它不起作用,您可以改用它:
If it doesn't work you could use this instead:
function int sumLengths(String[] strings) {
int counter = 0;
int length = (strings != null) ? strings.length : -1;
for (int idx = 0; idx < length; ++idx) {
counter += strings[idx].length();
}
return counter;
}
这篇关于Drools中的“无法找到课程"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文