Scala methods and functions
Translation results:
Scala is the abbreviation of Scalable Language and is a multi-paradigm programming language
Martin Odersky of the Ecole Polytechnique Fédérale de Lausanne (EPFL) began designing Scala in 2001 based on the work of Funnel.
Funnel is a programming language that combines functional programming ideas with Petri nets.
Scala methods and functionssyntax
Scala has methods and functions, and the semantic difference between them is very small. A Scala method is part of a class, while a function is an object that can be assigned to a variable. In other words, functions defined in a class are methods.
Methods in Scala are similar to those in Java. Methods are part of the class.
A function in Scala is a complete object. A function in Scala is actually an object of a class that inherits Trait.
In Scala, the val statement can be used to define functions, and the def statement can be used to define methods.
Scala methods and functionsexample
class Test{ def m(x: Int) = x + 3 val f = (x: Int) => x + 3 }