【发布时间】:2012-05-11 16:09:12
【问题描述】:
是否可以使用签名 Set<? extends Car> getCars() 模拟(使用 mockito)方法而没有抑制警告?我试过了:
XXX cars = xxx;
when(owner.getCars()).thenReturn(cars);
但无论我如何声明cars,我总是会遇到编译错误。
例如,当我这样声明时
Set<? extends Car> cars = xxx
我得到标准的通用/模拟编译错误
The method thenReturn(Set<capture#1-of ? extends Car>) in the type OngoingStubbing<Set<capture#1-of ? extends Car>> is not applicable for the arguments (Set<capture#2-of ? extends Car>)
【问题讨论】:
-
你遇到什么编译错误,你能复制/粘贴吗?
-
警告抑制、编译失败和异常都是不同的东西......我想你可能会在这里混淆它们。
-
我试图准确地解释一切。所以再次明确。我想编译我的代码。我也希望该代码没有警告,也没有
@SupressWarning。我从来没有提到任何关于例外的事情。希望有帮助 -
我同意它是 stackoverflow.com/questions/7366237/… 的副本,除了一个实际上是更新的,所以它不是副本。但它有更多的答案。并且可以争论一个更清晰的标题。