我已經在我的代碼使用的策略模式,這裏是一個簡短的片段:奇怪未檢查轉換警告
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'變量的類型? –