How does Scala define a type of return value? -


how scala define type of return value?

def sqrt = (x: int) =>   if (x > 0 && x < 4)     x * x 

the return type code int => anyval. if change to

def method = (x: string) =>   if (x.equals("abc"))     x.concat(x) 

the return type string => any. why not anyref? string object, better use anyref. wrong?

since if expression has no else, unit returned if condition evaluates false. unit extends anyval int, in first case specific type anyval. since string extends anyref, specific type any in second case.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -