JavaHamcrest icon indicating copy to clipboard operation
JavaHamcrest copied to clipboard

Allow Iterables in AllOf/AnyOf that are typed to an extension of `Mat……cher`

Open yankee42 opened this issue 8 years ago • 3 comments

Currently the following code won't compile:

List<Matcher<String>> submatchers = new ArrayList<>();
new AllOf<String>(submatchers);

This is because AllOf expects an Iterable<Matcher<? super String>> and not a Iterable<Matcher<String>> the I tried to supply above.

As a workaround this works:

List<Matcher<? super String>> submatchers = new ArrayList<>();
new AllOf<String>(submatchers);

But depending on where this list comes from it may be impracticable to change the type like that.

This also works, but generates a compile warning and right so...:

List<Matcher<String>> submatchers = new ArrayList<>();
new AllOf<String>((Iterable)submatchers);

This PR proposes a slight change in the method signature of AllOf, AnyOf and ShortcutCombination which eliminates the problem. The change in signature is compatible to the old API, because only the generics are changed.

yankee42 avatar Jul 16 '17 11:07 yankee42

@yankee42 wanting to kick start getting pr's getting reviewed and then merged, can you rebase from master, as hamcrest-core and hamcrest-library have been refactored a lot and also deprecated, so that everything is just in hamcrest.

nhojpatrick avatar Jun 29 '20 18:06 nhojpatrick

@nhojpatrick : I rebased it.

yankee42 avatar Jun 30 '20 14:06 yankee42

Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch v2.3-candidates. Still trying to understand how has permissions to perform a release.

nhojpatrick avatar Feb 13 '22 12:02 nhojpatrick