FutureTask,不安全的行动

时间:2012-10-23 09:52:26

标签: java futuretask

我在编写代码时遇到此警告(使用-Xlint选项):

receptor.java:286: warning: [unchecked] unchecked call to 
FutureTask(java.util.concurrent.Callable<V>) as a member 
of the raw type java.util.concurrent.FutureTask

生成警告的行:

FutureTask task = new FutureTask (new Return(address, lock));

Return类实现了Callable:

public class Return implements Callable <String> {

如何修复警告?

1 个答案:

答案 0 :(得分:3)

根据FutureTask documentation,这个类也是一个泛型类。这意味着你需要

FutureTask<String> task = new FutureTask<String>(new Return(address, lock));