Runnable Interface : Replace this lambda with a method reference. (sonar.java.source not set. Assuming 8 or greater.)

Viewed 651
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 Answers

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;
Related