There is no primitive types, everything is
Class Any is the root of the Scala class hierarchy.
numeric value types
non-numeric value types
There is no
scala.String in scala, on the JVM,
String is an alias for
Int, a 32-bit signed integer (equivalent to Java’s int primitive type) is a subtype of
scala.AnyVal. Scala stores integers in the same way as Java: as 32-bit words. This is important for efficiency on the JVM and also for interoperability with Java libraries.
Standard operations like addition or multiplication are implemented as primitive operations. However, Scala uses the “backup” class
java.lang.Integer whenever an integer needs to be seen as a (Java) object. This happens for instance when invoking the
toString method on an integer number or when assigning an integer to a variable of type
Integers of type
Int are converted transparently to “boxed integers” of type
java.lang.Integer whenever necessary.
There is an implicit conversion from
scala.Int => scala.runtime.RichInt which provides useful non-primitive operations.
For value types, it is the natural (numeric or boolean) equality. For reference types,
== is treated as an alias of the
equals method inherited from
Object. That method is originally defined as reference equality, but is overridden by many subclasses to implement their natural notion of equality.
AnyRef defines an additional
eq method, which cannot be overridden and is implemented as reference equality
refer to scala school for more content