O'Reilly logo

Pragmatic Scala by Venkat Subramaniam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Flexible Parameters and Arguments

Defining parameters and passing arguments are among the most common tasks we perform when programming in any language. Scala offers some nice facilities and conveniences to define variable numbers of arguments, declare default values for parameters, and define named arguments.

Passing Variable Arguments (Varargs)

Methods like println take a variable number of parameters. You can pass zero, one, or more arguments to such methods. In Scala you can create your own functions that can take a variable number of parameters.

We can design methods to take a variable number of arguments—varargs. However, if we have more than one parameter, only the trailing parameters can take a variable number of arguments. To indicate ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required