JavaHamcrest
JavaHamcrest copied to clipboard
Incorrect variance in `hasItem` matcher
The hasItem matcher has the signature
Matcher<Iterable<? super T>> hasItem(Matcher<? super T> itemMatcher)
but it should be
Matcher<Iterable<? extends T>> hasItem(Matcher<? super T> itemMatcher)
because the matcher needs to read items from the Iterable and it needs the contract that the sequence contains at least items of type T, so it should be covariant in T
The current implementation states the opposite, it would be applicable it the matcher wanted to write to the iterable, but that is (a) not possible, since there is no write operation on an iterable and (b) not its usecase.