问题
private void runAsyncImport() {
Runnable task = () -> runImport();
new Thread(task).start();
}
I am getting sonar issue for the above code, Replace this lambda with a method reference. (sonar.java.source not set. Assuming 8 or greater.)
How to fix it
回答1:
If your class has a non-static runImport() method,
then you can write like this:
Runnable task = this::runImport;
If the runImport() method is static, then instead of this, write the name of the class, for example if the name of the class is MyClass, then:
Runnable task = MyClass::runImport;
来源:https://stackoverflow.com/questions/46612287/runnable-interface-replace-this-lambda-with-a-method-reference-sonar-java-so