uczę Scala i nie może zrozumieć, dlaczego:Zwraca typ w przypadku wyrażenie
def signum(arg: Int) = {
if(arg > 0) 1
else if(arg < 0) -1
else 0
}
Has Int
jako typ zwracany signum (arg: Int): Int
Ale
def signum(arg: Int) = {
if(arg > 0) 1
else if(arg < 0) -1
else if(arg == 0) 0
}
Has AnyVal
signum (arg: Int): AnyVal
(co prawda nie jest łatwe do pełnotekstowego wyszukiwania dla: http://stackoverflow.com/questions/4038741/why-does-this-scala-line-return-a -unit –