scala
tutorials
Tour
What's new in Scala 3
Blog
About
Star
Methods · 10 of 42
✓
Method definition
In Scala methods are defined using
def
Methods that return a value must have an equal sign before the body of the method
Methods that have either a return statement or are recursive must declare a return type
← Useful operations
Contents
Next: Method definition 2
→
def add(x:Int, y:Int):Int = { return x + y } println(add(42,13))
Contents
✕
Scala basics
Overview
Scalculator
Operators are methods
Variables
Final variables
Printing values
String interpolation
String formatting
Useful operations
Method definition
Method definition 2
Method definition 3
Anonymous functions
Anonymous functions 2
Return multiple values
Declare multiple variables
Assign multiple variables
Loops using while
Loops using for
Loops without loops
If
Match as a switch
Arrays
Lists
Sets
Maps
Mutable collections
Collections: accessing elements
Collections: concatenation
Mutable collection operations
Immutable collections with var
Collections: useful methods
Classes
Classes, continued
What's new in Scala 3
Scala 3: what changed
Optional braces & new control syntax
Top-level definitions & @main
Enums & ADTs
Extension methods
given & using
Union & intersection types
Smaller niceties
Clear history