By Name Parameters in Scala PRO

When calling a function and passing over an argument which is an expression that needs to be evaluated, the expression will be evaluated before the function is invoked and its value will be passed over. This is the default behavior. By adding => in between the parameter name and its type we will defer the expression evaluation into the function execution and have it performed when its value is required.

package com.abelski

object Program
{
  def main(args: Array[String])
  {
    println(System.currentTimeMillis())
    printWithDelay(System.currentTimeMillis())
  }

  def printWithDelay( t: => Long) =
  {
    Thread.sleep(10000)
    println(t)
  }
}

The following video clips shows the execution of this code sample, overviews it and explains it.

Share:

banner for the css playlist in hebrew life michael courses for programmers

The First Steps in CSS

Learn CSS using our our videos (in Hebrew) on the CSS (he) playlist on youtube. Do it now. Do it for free.

Good Trainers Collaborate with Others

It is always essential to keep an open mind and learn from others. This applies to everyone, including teachers and especially software development trainers. Software

The Beauty of Code

Coding is Art! Developing Code That Works is Simple. Develop Code with Style is a Challenge!

Update cookies preferences