[java] Odd generics behavior

Related, but it is not exactly the same since the example in that post does compile under Java 8, which OP is using.

The errors actually give good information as to why type inference is not working. There are 3 different reasons.

java: no suitable method found for allOf(java.util.List<org.hamcrest.Matcher<java.lang.String>>)
    method org.hamcrest.core.AllOf.<T>allOf(java.lang.Iterable<org.hamcrest.Matcher<? super T>>) is not applicable
      (cannot infer type-variable(s) T
        (argument mismatch; java.util.List<org.hamcrest.Matcher<java.lang.String>> cannot be converted to java.lang.Iterable<org.hamcrest.Matcher<? super T>>))
    method org.hamcrest.core.AllOf.<T>allOf(org.hamcrest.Matcher<? super T>...) is not applicable
      (cannot infer type-variable(s) T
        (varargs mismatch; java.util.List<org.hamcrest.Matcher<java.lang.String>> cannot be converted to org.hamcrest.Matcher<? super T>))
    method org.hamcrest.core.AllOf.<T>allOf(org.hamcrest.Matcher<? super T>,org.hamcrest.Matcher<? super T>) is not applicable
      (cannot infer type-variable(s) T
        (actual and formal argument lists differ in length))

The last one (actual and formal arguments differ) is repeated a few times and is straightforward: only one parameter is given but the overloads require more than one parameter.

The second one (varargs mismatch) is also straightforward: you can give a bunch of Matchers to the method directly or in an array, but a List is not one of those nor can it be automatically converted to match.

Had OP used AllOf.allOf(isEmptyOrNullString(), isEmptyOrNullString()) both the 2-arg and vararg overloads would have applied, and the 2-arg would have been chosen.

So the first error (argument mismatch) is the real culprit, as that's the overload that's used with a List. The specific reason given is

/r/learnprogramming Thread