While type inference is not as powerful as we would like, in this case it really is the API that is to blame. He unreasonably restricts himself for no good reason. The is-empty connector works with any collection, not just collections of a specific one E.
, API
public class IsEmptyCollection implements Matcher<Collection<?>>
{
public static Matcher<Collection<?>> empty()
{
return new IsEmptyCollection();
}
}
assertThat(list, empty()) .
API.
@SuppressWarnings("unchecked")
public static Matcher<Collection<?>> my_empty()
{
return (Matcher<Collection<?>>)IsEmptyCollection.empty();
}