- Windows 10
- SonarLint 10.0.1.77000
- Java
For the code below:
List<Class<?>> m(Path path) throws IOException {
try (var stream = Files.walk(path)) {
return stream.map(p -> {
var className = p.toString();
try {
return Class.forName(className);
} catch (ClassNotFoundException e) {
return (Class<?>) null;
}
}).toList();
}
}
There is a lint that casting to Class<?> is unnecessary, and suggests its removal, however doing so would lead to a compilation failure (by IntelliJ and Maven).
Please note that “className = p.toString()” is not logical, but is is a shorthand for the deduction of the correct class name.