2
2
** ________ ___ / / ___ Scala API **
3
** / __/ __// _ | / / / _ | (c) 2002-2010, LAMP/EPFL **
3
** / __/ __// _ | / / / _ | (c) 2002-2013, LAMP/EPFL **
4
4
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
5
5
** /____/\___/_/ |_/____/_/ | | **
11
11
/** `AnyVal` is the root class of all ''value types'', which describe values
12
* not implemented as objects in the underlying host system. The value classes
13
* are specified in SLS 12.2.
12
* not implemented as objects in the underlying host system. Value classes
13
* are specified in Scala Language Specification, section 12.2.
15
15
* The standard implementation includes nine `AnyVal` subtypes:
24
* The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
25
* The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
26
* The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
24
* - The ''subrange types'' are [[scala.Byte]], [[scala.Short]], and [[scala.Char]].
25
* - The ''integer types'' include the subrange types as well as [[scala.Int]] and [[scala.Long]].
26
* - The ''floating point types'' are [[scala.Float]] and [[scala.Double]].
28
* Prior to Scala 2.10, `AnyVal` was a sealed trait. Beginning with Scala 2.10,
29
* however, it is possible to define a subclass of `AnyVal` called a ''user-defined value class''
30
* which is treated specially by the compiler. Properly-defined user value classes provide a way
31
* to improve performance on user-defined types by avoiding object allocation at runtime, and by
32
* replacing virtual method invocations with static method invocations.
34
* User-defined value classes which avoid object allocation...
36
* - must have a single, public `val` parameter that is the underlying runtime representation.
37
* - can define `def`s, but no `val`s, `var`s, or nested `traits`s, `class`es or `object`s.
38
* - typically extend no other trait apart from `AnyVal`.
39
* - cannot be used in type tests or pattern matching.
40
* - may not override `equals` or `hashCode` methods.
44
* class Wrapper(val underlying: Int) extends AnyVal {
45
* def foo: Wrapper = new Wrapper(underlying * 19)
49
* It's important to note that user-defined value classes are limited, and in some circumstances,
50
* still must allocate a value class instance at runtime. These limitations and circumstances are
51
* explained in greater detail in the [[http://docs.scala-lang.org/overviews/core/value-classes.html Value Classes Guide]]
52
* as well as in [[http://docs.scala-lang.org/sips/pending/value-classes.html SIP-15: Value Classes]],
53
* the Scala Improvement Proposal.
55
abstract class AnyVal extends Any with NotNull {
56
def getClass(): Class[_ <: AnyVal] = null