July 2018
Intermediate to advanced
242 pages
8h 6m
English
We've declared a default value for the initialSpeed parameter, equal to 0. Once we have a default value assigned, the initialSpeed parameter becomes an optional one. We can now omit it while invoking the function, as shown in the following example:
val displacement = calculateDisplacement(acceleration = 9.81f, duration = 1000)
Note that, if we are omitting some of the parameters and using their default values, we have to specify the values of the other parameters together with their names explicitly. This allows the compiler to map the values to the specific parameters. Of course, we are able to override the default value using the standard way:
val displacement = calculateDisplacement(10f, 9.81f, 1000)
Read now
Unlock full access