3

我正在尝试定义一个非常简单的函数,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>' ]

任何的想法?

4

2 回答 2

7

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

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;
}
于 2012-06-19T07:20:38.340 回答
-1

改成

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

......

 celda c = (celda) celdas.get(y);
}
于 2018-04-26T03:53:47.933 回答