这里一般返回类型的方法是我的问题:模拟用的Mockito
public interface Containter extends ModelElement{
List<? extends ModelElement> getChildren();
}
有几类实现Containter,我想嘲笑他们:
public class MockMama {
public static <T extends Containter, Y extends ModelElement> T bornContainer(Class<T> clazz, Y ... children) {
T container = mock(clazz);
when(container.getChildren()).thenReturn(Arrays.asList(children));
return container;
}
}
但是这并未没有工作。 Eclipse说:“然后返回(List)类型的OngoingStubbing>方法不适用于参数(List)”。我也尝试传递类型List <? extends ModelElement>
的本地声明变量然后返回,但这也没有帮助。
任何帮助,高度赞赏和欢迎:)
好吧,它看起来可以通过引入额外的本地变量来修复,如 List list = Arrays.asList(children); when(container.getChildren())。thenReturn(list); 有没有办法做到这一点,而不会导致原始类型警告? – user656449 2011-12-23 12:29:31