Sonar rule S1604 raises an issue to convert an anonymous inner class to a lambda even if the method has type parameters.
But lambda expression cannot be used in this case.
See: https://stackoverflow.com/questions/22588518/lambda-expression-and-generic-method
Versions:
SonarQube: Version 6.7.2 (build 37468)
SonarJava: 5.11 (build 17289)
Hello,
Can you share a reproducer so we can be sure of the use case you are talking about?
Thanks
Sorry for the long delay:
import java.util.Arrays;
import java.util.List;
public class Repro {
public static void main(String[] args) {
List<String> list = Arrays.asList("a", "b", "c");
sort(list, new MyComparable() {
@Override
public <T extends Comparable<T>> int compare(T obj1, T obj2) {
return 0;
}
});
}
public static <T extends Comparable<T>> void sort(List<T> list, MyComparable comp) {
//
}
}
interface MyComparable {
public <T extends Comparable<T>> int compare(T obj1, T obj2);
}
Lena
(Elena Vilchik)
July 2, 2019, 12:02pm
4
Hi,
Thanks a lot for the reproducer, I’ve created a ticket to fix this FP.
system
(system)
Closed
April 8, 2021, 9:29am
5
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.