Difference between method and function in Scala

后端 未结 9 2043
温柔的废话
温柔的废话 2020-11-21 07:22

I read Scala Functions (part of Another tour of Scala). In that post he stated:

Methods and functions are not the same thing

9条回答
  •  广开言路
    2020-11-21 08:01

    function A function can be invoked with a list of arguments to produce a result. A function has a parameter list, a body, and a result type. Functions that are members of a class, trait, or singleton object are called methods. Functions defined inside other functions are called local functions. Functions with the result type of Unit are called procedures. Anonymous functions in source code are called function literals. At run time, function literals are instantiated into objects called function values.

    Programming in Scala Second Edition. Martin Odersky - Lex Spoon - Bill Venners

提交回复
热议问题