在单元测试中,我有这样的代码:
@Mock
private AbstractCacheImpl<?> cache;
@Before
public void setup() {
xxxx.setCacheImplementations(Arrays.asList(cache)); // error
}
在“error”行,eclipse(和命令行javac)说:
The method setCacheImplementations(List<AbstractCacheImpl<?>>) in the type xxxx is
not applicable for the arguments (List<Object>)
这是方法定义:
void setCacheImplementations(List<AbstractCacheImpl<?>> cacheImplementations) { this.cacheImplementations = cacheImplementations; }
我也见过类似的问题,我也尝试过不同的解决方案,但我还没有找到解决方案。
我尝试了“的变化”
Arrays.<stuff>asList(...)
“但这些都没有任何效果。
我甚至尝试将“aslist()”的整个返回值强制转换为预期的返回类型,但这也不起作用。它只是说我不能将返回值强制转换为该类型。