estoy aprendiendo Scala y no puede entender por qué:Tipo de retorno en la expresión Si
def signum(arg: Int) = {
if(arg > 0) 1
else if(arg < 0) -1
else 0
}
Ha Int
como tipo de retorno signum (arg: Int): Int
Pero
def signum(arg: Int) = {
if(arg > 0) 1
else if(arg < 0) -1
else if(arg == 0) 0
}
tiene AnyVal
signum (arg: Int): AnyVal
(ciertamente no es fácil de búsqueda de texto completo para: http://stackoverflow.com/questions/4038741/why-does-this-scala-line-return-a -unit –