最初,我有这段生产代码:
interface ActionSequence {
public List<Actions> getActions();
我测试了实现该接口的类,如下所示:
assertThat(sequenceUnderTest.getActions(), is(Arrays.asList(action1, action2));
然后我认为将生产界面更改为:
public List<? extends Action> getActions() {
(允许我返回 Action 的子类列表)。
但现在日食告诉我:
The method assertThat(T, Matcher<? super T>) in the type Assert is not applicable for the arguments (List<capture#1-of ? extends Action>, Matcher<List<Action>>)
我想:当我更改实现 ActionInterface的类时
@Override
public List<SomeSubClassOfAction> getActions()
(而不是保留通配符)......然后一切正常。但为什么?