deprecation warning when compiling: eta expansion of zero argument method

Viewed 2385

When compiling this snippet, the scala compiler issues the following warning:

Eta-expansion of zero-argument method values is deprecated. Did you intend to write Main.this.porFiles5()? [warn] timerFunc(porFiles5)

It occurs when I pass a function to another one for a simple timing. The timer function takes a parameterless function returning unit, at this line: timerFunc(porFiles5). Is this warning necessary? What would be the idiomatic way to avoid it?

package example
import java.nio.file._
import scala.collection.JavaConverters._
import java.time._
import scala.collection.immutable._

object Main extends App {

  val dir = FileSystems.getDefault.getPath("C:\\tmp\\testExtract")

  def timerFunc (func:()=>Unit ) = {
    val start = System.currentTimeMillis()
    timeNow()
    func()
    val finish = System.currentTimeMillis()
    timeNow()
    println((finish - start) / 1000.0 + " secs.")
    println("==================")
  }

  def porFiles5(): Unit = {
    val porFiles5 = Files.walk(dir).count()
    println(s"You have $porFiles5 por5 files.")
  }

  def timeNow(): Unit = {
    println(LocalTime.now)
  }

  timeNow()
  timerFunc(porFiles5)
  timeNow()

}
1 Answers
Related