If this is Java 7+, then the library you're using can annotate the method with @SafeVarargs
. However, this is not under your control.
Otherwise there is no way to avoid an unchecked warning with this method, because the method fundamentally requires an array of a parameterized type, and it is impossible to obtain a non-null
value of this type without an unchecked operation somewhere (either in your method or some other method that you call).
Or, looking at the documentation for CoreMatchers
, it seems that you could consider using the alternate overload of the allOf
, which takes an Iterable
of matchers instead. That you can use without unchecked operations.