If I call a method, that returns a genericly typed object, that could be specialized and I don’t have control over that method itself or the method is more general and cannot be specialized, I have no choice, but to define the variable the same way.
public interface I
{
<T> Supplier<T> foo( T sample );
}
I iii = ...;
Supplier<Long> s = iii.foo( 1234L ); // FP
S4276 suggest to use the more specialized type LongSupplier, which is wrong here, because
- the method returns the type as that.
- the method is more general and correctly uses Supplier.