Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Tags
#odersky-programming-in-scala-1ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
a factory method apply which takes variable number of argumetns and is defined on Array companion object
the code gets transformed to
val numNames2 = Array.apply("zero", "one", "two")

Tags
#odersky-programming-in-scala-1ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
?

Tags
#odersky-programming-in-scala-1ed #scala
Question
What method are you calling here and where is it defined?
val numNames = Array("zero", "one", "two")
Answer
a factory method apply which takes variable number of argumetns and is defined on Array companion object
the code gets transformed to
val numNames2 = Array.apply("zero", "one", "two")
If you want to change selection, open document below and click on "Move attachment"

Next Steps in Scala
his code creates a new array of length three, initialized to the passed strings, "zero", "one", and "two". The compiler infers the type of the array to be Array[String], because you passed strings to it. <span>val numNames = Array("zero", "one", "two") Listing 3.2 - Creating and initializing an array. What you're actually doing in Listing 3.2 is calling a factory method, named apply, which creates and returns the new array. This apply method takes a variable number of arguments[2] and is defined on the Array companion object. You'll learn more about companion objects in Section 4.3. If you're a Java programmer, you can think of this as calling a static method named apply on class Array. A more verbose way to call the same apply method is: val numNames2 = Array.apply("zero", "one", "two") Step 8. Use lists [link] One of the big ideas of the functional style of programming is that methods should not have side effects. A method's only act should be to compute and return

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.