Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Call by Value, Name, Need

Exercise 1

  1. Make it a call by name
  2. Make it a call by need by adding a lazy val
def exercise(str: String) = 
  
  Thread.sleep(2000)
  println(s"first: $str at ${System.nanoTime()}")

  Thread.sleep(2000)
  println(s"second: $str at ${System.nanoTime()}")

exercise("hello")

Exercise 2

Create a function def currentTime(time: Long)

  1. Make it a call by value
  2. Make it a call by name
  3. Make it a call by need by adding a lazy val