scala

AnyVal

abstract class AnyVal extends Any

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 of AnyVal 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...

A minimal example:

class Wrapper(val underlying: Int) extends AnyVal {
def foo: Wrapper = new Wrapper(underlying * 19)
}

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 Guide as well as in SIP-15: Value Classes, the Scala Improvement Proposal.

Source
AnyVal.scala
Linear Supertypes
Any
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. AnyVal
  2. Any
Implicitly
  1. by StringAdd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new AnyVal()

Value Members

  1. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  2. final def ##(): Int

    Definition Classes
    Any
  3. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from AnyVal to StringAdd[AnyVal] performed by method StringAdd in scala.Predef.
    Definition Classes
    StringAdd
  4. def ->[B](y: B): (AnyVal, B)

    Implicit information
    This member is added by an implicit conversion from AnyVal to ArrowAssoc[AnyVal] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def ensuring(cond: (AnyVal) ⇒ Boolean, msg: ⇒ Any): AnyVal

    Implicit information
    This member is added by an implicit conversion from AnyVal to Ensuring[AnyVal] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  8. def ensuring(cond: (AnyVal) ⇒ Boolean): AnyVal

    Implicit information
    This member is added by an implicit conversion from AnyVal to Ensuring[AnyVal] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  9. def ensuring(cond: Boolean, msg: ⇒ Any): AnyVal

    Implicit information
    This member is added by an implicit conversion from AnyVal to Ensuring[AnyVal] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  10. def ensuring(cond: Boolean): AnyVal

    Implicit information
    This member is added by an implicit conversion from AnyVal to Ensuring[AnyVal] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  11. def equals(arg0: Any): Boolean

    Definition Classes
    Any
  12. def formatted(fmtstr: String): String

    Returns string formatted according to given format string.

    Returns string formatted according to given format string. Format strings are as for String.format (@see java.lang.String.format).

    Implicit information
    This member is added by an implicit conversion from AnyVal to StringFormat[AnyVal] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  13. def getClass(): Class[_ <: AnyVal]

    Definition Classes
    AnyVal → Any
  14. def hashCode(): Int

    Definition Classes
    Any
  15. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  16. def toString(): String

    Definition Classes
    Any
  17. def [B](y: B): (AnyVal, B)

    Implicit information
    This member is added by an implicit conversion from AnyVal to ArrowAssoc[AnyVal] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Inherited from Any

Inherited by implicit conversion StringAdd from AnyVal to StringAdd[AnyVal]

Inherited by implicit conversion StringFormat from AnyVal to StringFormat[AnyVal]

Inherited by implicit conversion Ensuring from AnyVal to Ensuring[AnyVal]

Inherited by implicit conversion ArrowAssoc from AnyVal to ArrowAssoc[AnyVal]

Ungrouped