Hi there, i’m just starting reading Programming in scala and in chapter 3 it raised me a (probably dumb) question.
If i have this code:
val greetings = new Array[String](1)
greetings(0) = "teste"
This will be equivalent to:
val greetings = new Array[String](1)
greetings.update(0, "teste")
But, if greeting(0) will call greeting.apply(0) and apply method will return a String, so why the compiler are not looking to some kind of attribution in the string returned from greeting(0)? I think this would fail in this case, but, why the first example above works? It’s just a matter of “compiler knows” or it is a method from the Arrays Trait?
Thanks in advance.