Drools中的“无法找到课程”错误

MBZ*_*MBZ 3 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;
}
Run Code Online (Sandbox Code Playgroud)

但这给了我错误:

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>' ]
Run Code Online (Sandbox Code Playgroud)

任何的想法?

Ale*_*exS 5

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

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

如果它不起作用,您可以改用以下方法:

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;
}
Run Code Online (Sandbox Code Playgroud)