Scala Expressions Evaluation PRO

When creating a variable using val or var and assigning the value of an expression into it the expression is evaluated when the variable is created. When creating a function using def and assigning the value of an expression to it the expression is evaluated when calling the function.

object Program {
  def main(args: Array[String]):Unit =
  {
    var a = 3
    var b = 4
    var c = 5
    val e1 = if (b>a) "spiderman" else "wonderwoman"
    var e2 = if (b>a) "spiderman" else "wonderwoman"
    def e3 = if (b>a) "spiderman" else "wonderwoman"
    a = 7
    println(e1)
    println(e2)
    println(e3)
  }
}

The following video clip goes over this code sample 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