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:

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