-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic type bounds of IsIterableContaining are inconsistent with those of IsMapContaining #252
Comments
Writing library code with Java generics is a bit like (╯ರ ~ ರ)╯︵ ┻━┻ Perhaps @sf105 might have some insights as to how the current implementation came to be the way it is? |
Collection<Banana> bananas = singleton(banana);
Collection<Fruit> fruits = singleton(banana);
assertThat(fruits, hasItem(banana));
assertThat(bananas, hasItem(fruit) ); // this one is currently invalid I think this makes sense: Why would I want to check if a collection of some specific type contains some less specific type? Usually I already know the actual runtime type of the value I use to create the matcher with, because I create it myself, whereas the collection being examined is passed in and could be anything. The same is true for maps. Therefore I would propose to make the |
The IsIterableContaining have to extend So, you want to construct Matcher that take the Iterable<? extends Car> and apply to it given Matcher<? super Car> |
I've been reading up on poloymorphic collections in Java, and the PECS rule (producer extends, consumer super). I've created #422 as an attempt to address this issue. There's a new test in I'm a bit worried that this change might impact a lot of existing code. I'd appreciate if folks could check out that fork and give it a test |
Hello all! Thanks a lot for the new Hamcrest 2.1 library, it's a pleasure to work with and I can also use it easily in my Java 9 modules.
The
IsIterableContaining
matcher extendsTypeSafeDiagnosingMatcher<Iterable<? super T>>
. I understand that the goal is to, for instance, match aSet<Number>
when it has anInteger
.Why then does
IsMapContaining
extendTypeSafeMatcher<Map<? extends K, ? extends V>>
? Wouldn't it be just as reasonable to match aMap<Object, Object>
when it has aString
key? Or aLong
value?The text was updated successfully, but these errors were encountered: