class Algo {
def a( a : String = "Hola ", b : String = "adios" ) {
print( a )
print( b )
}
def a() {
print ("Uh?")
}
}
object Algo {
def main( args : Array[String] ) {
new Algo().a()
}
}
prints Uh?
If method a()
is not defined, the code prints "Hola adios" using the default values.
So, I deduce, from this, that, if an exact signature is match, that is preffered.
Is this reasoning correct?
Scala - Functions with Named Arguments Named arguments allow you to pass arguments to a function in a different order. The syntax is simply that each argument is preceded by a parameter name and an equals sign. Try the following program, it is a simple example to show the functions with named arguments.
Java and Scala both use call by value exclusively, except that the value is either a primitive or a pointer to an object. If your object contains mutable fields, then there is very little substantive difference between this and call by reference.
When you pass an argument by name, you specify the argument's declared name followed by a colon and an equal sign ( := ), followed by the argument value.
By-name parameters are evaluated every time they are used. They won't be evaluated at all if they are unused. This is similar to replacing the by-name parameters with the passed expressions. They are in contrast to by-value parameters. To make a parameter called by-name, simply prepend => to its type.
This behavior is clearly defined in SID #1, section 3.1.
Overloading Resolution In a method application expression, when multiple overloaded alternatives are applicable, the alternative which use default arguments is never selected.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With