Emoticons 11.1 Scala class level diagram
Emoticons 11.1 shows the Scala class-level outline. The top of the hierarchy is the class any, which defines the methods that include the following:
Final def = = (That:any): Boolean
final def!= (That:any): Boolean
def equals (That:any): Boolean
def has Hcode:int
def tostring:string
Because each class inherits from the Any,scala program, each object can be compared with ==,!= or equals, with a hashcode hash, and with ToString format. The Equals and!= in the class any, = = and the same, are declared final, so they cannot be overloaded within subclasses. In fact, = = always the same as equals,!= is always the opposite of equals. Therefore, a separate class can trim the meaning of = = or!= by overloading the Equals method. We'll show you an example later in this chapter.
The root class any has two subclasses: Anyval and Anyref. Anyval is the parent class of each built-in value class in Scala. There are nine such value classes: Byte,short, Char,int,long,float,double,boolean and unit. The first eight of these correspond to the original Java type, whose values are represented at runtime as the original Java values. In Scala, instances of these classes are written in text. For example, 42 is an instance of int, ' X ' is an instance of char, and false is an instance of Boolean. You cannot use new to create instances of these classes. This is "small trick", the value class are defined as that is the abstract and final, mandatory implementation. So if you have written:
Scala> New Int
You will get:
< Console>:5:error:class Int is abstract; Cannot be
instantiated
new Int
ˆ