I just looked at both and methods at org.hamcrest.core.CombinableMatcher in hamcrest 1.2
For some reason I cannot get the following command to compile
@Test public void testBoth() { String HELLO = "hello"; String THERE = "there"; assertThat("hello there", both(containsString(HELLO)).and(containsString(THERE))); }
The compilation message I receive is
and(org.hamcrest.Matcher<? super java.lang.Object>) in org.hamcrest.core.CombinableMatcher<java.lang.Object> cannot be applied to (org.hamcrest.Matcher<java.lang.String>)
If I specify a type expression for a method, it works
@Test public void testBoth() { String HELLO = "hello"; String THERE = "there"; Assert.assertThat("hello there", CombinableMatcher.<String> both(containsString(HELLO)).and(containsString(THERE))); }
Although it is not so nice.
Can someone tell me why the compiler cannot define types here? I cannot believe that this is the expected behavior in this case.
Thanks!
source share