【发布时间】:2012-12-28 13:01:49
【问题描述】:
我在我的代码中使用了策略模式,这是一个简短的片段:
public interface FindingStrategy<T> {
Callable<T> setAction();
}
class FindSomething implements BindingActionStrategy {
...
@Override
public Callable<SomeObject> setAction() {
return new Callable<SomeObject>() {
@Override
public SomeObject call() throws ... {
return (SomeObject)binding.findSomething(somethingsId);
}
};
}
...
}
我做的其他地方:
Callable<SomeObject> ts = (Callable<SomeObject>) strategy.setAction();
以及编译器信号:
unchecked conversion warning
required: Callable<SomeObject>
found: Callable
奇怪的是,如果我这样做,没有警告:
Callable<SomeObject> ts = new Callable<SomeObject>() {
@Override
public SomeObject call() throws ... {
return (SomeObject)binding.findSomething(somethingsId);
}
};
我该如何解决这个问题?我试图改变很多,但我仍然收到警告。请帮忙!
【问题讨论】:
-
strategy变量的类型是什么?