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:

The Visitor Design Pattern

The Visitor Design Pattern

The visitor design pattern allows us to add operations to objects that already exist without modifying their classes and without extending them.

What are Anti Patterns?

Anti Patterns

Unlike design patterns, anti patterns just seem to be a solution. However, they are not a solution and they cause additional costs.

Virtual Threads in Java Professional Seminar

Virtual Threads in Java

The use of virtual threads can assist us with improving the performance of our code. Learn how to use virtual threads effectively.

The Beauty of Code

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

Update cookies preferences