SONARJAVA-2795 removed FP when the call is ambiguous and can not be replaced by a lambda.
It uses a heuristic to identify if a method can be ambiguous:
suitable method is instance method with no parameters, or static method with single parameter of the same type as lambda argument
The last part is not precise enough, the lambda argument type can also be a subtype. If it is the case, the rule will still report FP.
public class S1612 { public static void main(String[] args) { Function<B, String> f = a -> a.f(); // FP , A::f can't be used } } class A { String f() { return ""; } static String f(A a) { return ""; } } class B extends A { }
- relates to
-
SONARJAVA-2795 FP S1612 method reference shouldn't be suggested when resolution is ambiguous
-
- Closed
-
- links to