abstract
class
AnyVal extends Any
Instance Constructors
-
new
AnyVal()
Value Members
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
equals(arg0: Any): Boolean
-
def
getClass(): Class[_ <: AnyVal]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
def
toString(): String
AnyVal
is the root class of all value types, which describe values not implemented as objects in the underlying host system. Value classes are specified in Scala Language Specification, section 12.2.The standard implementation includes nine
AnyVal
subtypes:scala.Double, scala.Float, scala.Long, scala.Int, scala.Char, scala.Short, and scala.Byte are the numeric value types.
scala.Unit and scala.Boolean are the non-numeric value types.
Other groupings:
Prior to Scala 2.10,
AnyVal
was a sealed trait. Beginning with Scala 2.10, however, it is possible to define a subclass ofAnyVal
called a user-defined value class which is treated specially by the compiler. Properly-defined user value classes provide a way to improve performance on user-defined types by avoiding object allocation at runtime, and by replacing virtual method invocations with static method invocations.User-defined value classes which avoid object allocation...
val
parameter that is the underlying runtime representation.def
s, but noval
s,var
s, or nestedtraits
s,class
es orobject
s.AnyVal
.equals
orhashCode
methods.A minimal example:
It's important to note that user-defined value classes are limited, and in some circumstances, still must allocate a value class instance at runtime. These limitations and circumstances are explained in greater detail in the Value Classes and Universal Traits.