这是我的代码的一小部分。我在第 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 toFuture<String>[]
- Type safety: The expression of typeFuture[]
needs unchecked conversion to conform toFuture<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/