我试图在Java 8中了解泛型和通配符.但我无法理解为什么不能模拟这个存储库方法.代码非常简单,因此应该很容易重现.
我在"thenReturn"部分的"when"中得到了这个编译错误
The method thenReturn(Stream<capture#1-of ? extends Something>) in the type
OngoingStubbing<Stream<capture#1-of ? extends Something>> is not applicable
for the arguments (Stream<capture#3-of ? extends Something>)
Run Code Online (Sandbox Code Playgroud)
考试:
@Test
public void ItShourReturnStreamFromRepository() {
List<Something> list = new ArrayList<Something>();
list.add(new Something());
Stream<? extends Something> stream = list.stream();
when(someRepository.getStream()).thenReturn(stream);
}
Run Code Online (Sandbox Code Playgroud)
班级:
public class Something {}
Run Code Online (Sandbox Code Playgroud)
存储库:
public interface SomeRepository{
Stream<? extends Something> getStream();
}
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?谢谢!