Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the responsive-lightbox domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114

Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the hueman domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/www/wp-includes/functions.php on line 6114
Scala - Function with named parameters - Testingpool

Scala – Function with named parameters

In Scala, we can write the function with default parameters as we have seen in the last post.Now, we will see how to pass parameters with some name. We can pass named parameters in any order and can also pass parameters without name. Let’s understand with an example.

object FuncWithDefaultParam {
  def main(args: Array[String]): Unit = {

    println("a=2,b=3 - Result: "+addition(a=2,b=3))  //Passed parameter names in same sequence /Result : 2 + 3
    println("b=3,a=2 - Result: " + addition(b=3,a=2))  //Passed parameters names with changed sequence/Result : 2 + 3
    println("2,3 - Result: " +addition(2,3))  //Passing only values /Result : 2 + 3
  }

  def addition(a:Int=0,b:Int=0): Int ={
    a + b
  }
}
a=2,b=3 - Result: 5
b=3,a=2 - Result: 5
2,3 - Result: 5
Avatar photo

Shekhar Sharma

Shekhar Sharma is founder of testingpool.com. This website is his window to the world. He believes that ,"Knowledge increases by sharing but not by saving".

You may also like...