gpt4 book ai didi

java - Drools 中的 `Unable to find class` 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:22:00 34 4
gpt4 key购买 nike

我正在尝试在 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>' ]

有什么想法吗?

最佳答案

也许这是泛型的问题(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;
}

关于java - Drools 中的 `Unable to find class` 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11062657/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com