How Scala knows which method to call (named parameters)

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 the method is a()not defined, the code prints "Hola adios" using the default values.

So, I inferred from this that if the exact signature matches, it is preferable.

Is this reasoning correct?

+5
source share
2 answers

This behavior is clearly defined in SID # 1 , section 3.1.

Overload Resolution In a method application expression, when several alternatives are overloaded, an alternative that uses the default arguments is never selected.

+13
source

. , .

, - .

0

All Articles