July 2017
Intermediate to advanced
796 pages
18h 55m
English
One surprising thing about Scala is that the body of a Scala class is itself a constructor. However, Scala does so; in fact, in a more explicit way. After that, a new instance of that class is created and executed. Moreover, you can specify the arguments of the constructor in the class declaration line.
Consequently, the constructor arguments are accessible from all of the methods defined in that class. For example, the following class and constructor definition is valid in Scala:
class Hello(name: String) { // Statement executed as part of the constructor println("New instance with name: " + name) // Method which accesses the constructor argument def sayHello = println("Hello, " + name + "!")}
The equivalent Java class ...
Read now
Unlock full access