You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, Java requires use-site type variance, so if someone has Function<IN, OUT> method parameter, it should rather be Function<? super IN, ? extends OUT>.
Unfortunately, it is not easy to notice that ? super and ? extends is missing, so it would be nice if there was a tool that could detect missing variance and suggest adding it.
The list of well-known classes could be hard-coded within ErrorProne: Function, Predicate, BiFunction, Consumer, Supplier, and so on.
+1 there is a well-known set of known-co(ntra)variant types and, at least for public methods, skipping the wildcard is virtually never okay.
An exception could be made for Predicate<Object>, but ironically, adopting JSpecify-type nullness analysis messes that one up! (You do need Predicate<? super Object> sometimes, since Object is no longer the top type, @Nullable Object is).
See:
Currently, Java requires use-site type variance, so if someone has
Function<IN, OUT>
method parameter, it should rather beFunction<? super IN, ? extends OUT>
.Unfortunately, it is not easy to notice that
? super
and? extends
is missing, so it would be nice if there was a tool that could detect missing variance and suggest adding it.The list of well-known classes could be hard-coded within ErrorProne:
Function
,Predicate
,BiFunction
,Consumer
,Supplier
, and so on.Here a recent case:
WDYT?
See also:
/cc @Stephan202
The text was updated successfully, but these errors were encountered: