#odersky-programming-in-scala-1ed #scala
accessing an
element of an array in Scala is simply a method call like any other.
This principle is not restricted to arrays: any application
of an object to some arguments in parentheses will be transformed to an apply method call. Of
course this will compile only if that type of object actually defines an apply method.
If you want to change selection, open document below and click on "Move attachment"
Next Steps in Scalain
Scala. When you apply parentheses surrounding one or more values to a variable, Scala will transform the code into an invocation of
a method named apply on that variable. So greetStrings(i) gets transformed into greetStrings.apply(i). Thus <span>accessing an
element of an array in Scala is simply a method call like any other.
This principle is not restricted to arrays: any application
of an object to some arguments in parentheses will be transformed to an apply
method call. Of
course this will compile only if that type of object actually defines an apply method.
So it's not a special case; it's a general rule.
Similarly, when an assignment is made to a variable to which parentheses and one or more arguments have
been applied, the compiler wil Summary
status | not read | | reprioritisations | |
---|
last reprioritisation on | | | suggested re-reading day | |
---|
started reading on | | | finished reading on | |
---|
Details