1.

What is a by-name parameter in Scala?

Answer»

Scala allows passing a block of code in a function which is evaluated only when it is used. This kind of parameters are called a by-name parameter. By-name parameters are often used while DEFINING a new CONTROL structure. Let’s take an example.

DEF executionTime(f: => Any) = { val start = System.currentTimeMillis() f System.currentTimeMillis() - start } val t = executionTime { gcdList(List(18, 24, 36)) }


Discussion

No Comment Found