gpt4 book ai didi

Java 编程 ---> future [输入。长度 ]

转载 作者:行者123 更新时间:2023-11-29 08:05:55 25 4
gpt4 key购买 nike

这是我的代码的一小部分。我在第 4 行收到警告,也就是这一行:

Future<String>[] results = new Future[inputs.length]; // Stores the results

警告基本上在[inputs.length]部分原因是我无法执行 for 循环。警告是:

Multiple markers at this line - Type safety: The expression of type Future[] needs unchecked conversion to conform to Future<String>[] - Type safety: The expression of type Future[] needs unchecked conversion to conform to Future<String>[]

您能否建议一种方法,我不必更改 for 循环,但可以从第 4 行删除警告?

public StringBuilder fieldAggregator(String... inputs)
throws InterruptedException, ExecutionException {
StringBuilder sb = new StringBuilder();
Future<String>[] results = new Future[inputs.length]; // Stores the results
for (int i = 0; i < inputs.length; i++) { // Submits the tasks to thread pool
results[i] = pool.submit(new ValidateInput<String>(inputs[i], pool));
}
for (int i = 0; i < inputs.length; i++) { // Aggregates the results
sb.append(results[i].get());
}
return sb;
}

最佳答案

具有泛型类型参数的数组不存在。请改用集合。

关于Java 编程 ---> future [输入。长度 ],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11286439/

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