10 Method definition 2

  • return keyword is optional
  • Return type is inferred (for non recursive methods and methods that don’t have an explicit return value)

0
def add(x:Int, y:Int) = { //result type is inferred   
1
  x + y //"return" keyword is optional  
2
}  
3
println(add(42,13))  
4
 
 
Code editor is using Scalakata.com written by Guillaume Massé