When you declare Predicate<? extends Number> isGreaterThanZero
, you are telling the compiler that isGreaterThanZero
is a Predicate
parametrized by some unknown subtype of Number
.
As far as the compiler knows, it could be a Predicate<Double>
or a Predicate<BigInteger>
. Can you safely pass an Integer
to test(Double x)
or to test(BigInteger x)
? You cannot. The only thing that you can safely pass to test
method of Predicate<? extends Number>
is null
.
If you want isGreaterThanZero
to be a predicate that works on any subtype of Number
, you should declare it as Predicate<Number>
.