在Drools中“无法找到类”错误

时间:2012-06-16 10:30:06

标签: java jboss drools

我正在尝试在Drools中定义一个非常简单的函数,如下所示:

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>' ]

任何想法?

2 个答案:

答案 0 :(得分:5)

也许这是泛型问题(This指出了我的结论)。您是否尝试过以下(或类似):

function int sumLengths(List strings) {
    int counter = 0;
    for (Object s : strings)
        counter += ((String) s).length();
    return counter;
}

如果它不起作用,你可以改用它:

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;
}

答案 1 :(得分:-1)

更改为

function Boolean consulta(celda cref, java.util.List celdas) {

......

 celda c = (celda) celdas.get(y);
}