September 2018
Intermediate to advanced
398 pages
9h 43m
English
We mentioned earlier that all Scala expressions have a type. A class is a sort of template that can create objects of a specific type. When we want to obtain a value of a certain type, we can instantiate a new object using new followed by the class name:
scala> class Robotdefined class Robotscala> val nao = new Robotnao: Robot = Robot@78318ac2
The instantiation of an object allocates a portion of heap memory in the JVM. In the preceding example, the value nao is actually a reference to the portion of heap memory that keeps the content of our new Robot object. You can observe that when the Scala console printed the variable nao, it outputted the name of the class, followed by @78318ac2. This hexadecimal number is, in fact, the memory ...
Read now
Unlock full access