scala

Predef

object Predef extends LowPriorityImplicits with DeprecatedPredef

The Predef object provides definitions that are accessible in all Scala compilation units without explicit qualification.

Commonly Used Types

Predef provides type aliases for types which are commonly used, such as the immutable collection types scala.collection.immutable.Map, scala.collection.immutable.Set, and the scala.collection.immutable.List constructors (scala.collection.immutable.:: and scala.collection.immutable.Nil).

Console I/O

Predef provides a number of simple functions for console I/O, such as print, println, readLine, readInt, etc. These functions are all aliases of the functions provided by scala.Console.

Assertions

A set of assert functions are provided for use as a way to document and dynamically check invariants in code. assert statements can be elided at runtime by providing the command line argument -Xdisable-assertions to the scala command.

Variants of assert intended for use with static analysis tools are also provided: assume, require and ensuring. require and ensuring are intended for use as a means of design-by-contract style specification of pre- and post-conditions on functions, with the intention that these specifications could be consumed by a static analysis tool. For instance,

def addNaturals(nats: List[Int]): Int = {
  require(nats forall (_ >= 0), "List contains negative numbers")
  nats.foldLeft(0)(_ + _)
} ensuring(_ >= 0)

The declaration of addNaturals states that the list of integers passed should only contain natural numbers (i.e. non-negative), and that the result returned will also be natural. require is distinct from assert in that if the condition fails, then the caller of the function is to blame rather than a logical error having been made within addNaturals itself. ensures is a form of assert that declares the guarantee the function is providing with regards to it's return value.

Implicit Conversions

A number of commonly applied implicit conversions are also defined here, and in the parent type scala.LowPriorityImplicits. Implicit conversions are provided for the "widening" of numeric values, for instance, converting a Short value to a Long value as required, and to add additional higher-order functions to Array values. These are described in more detail in the documentation of scala.Array.

Linear Supertypes
DeprecatedPredef, LowPriorityImplicits, AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Predef
  2. DeprecatedPredef
  3. LowPriorityImplicits
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Type Members

  1. sealed abstract class <:<[-From, +To] extends (From) ⇒ To with Serializable

    An instance of A <:< B witnesses that A is a subtype of B.

  2. sealed abstract class =:=[From, To] extends (From) ⇒ To with Serializable

    An instance of A =:= B witnesses that the types A and B are equal.

  3. implicit final class ArrayCharSequence extends CharSequence

  4. implicit final class ArrowAssoc[A] extends AnyVal

  5. type Class[T] = java.lang.Class[T]

  6. class DummyImplicit extends AnyRef

    A type for which there is always an implicit value.

  7. implicit final class Ensuring[A] extends AnyVal

  8. type Function[-A, +B] = (A) ⇒ B

  9. type Manifest[T] = reflect.Manifest[T]

    Annotations
    @implicitNotFound( msg = "No Manifest available for ${T}." )
  10. type Map[A, +B] = collection.immutable.Map[A, B]

  11. type OptManifest[T] = reflect.OptManifest[T]

  12. implicit final class RichException extends AnyVal

  13. implicit final class SeqCharSequence extends CharSequence

  14. type Set[A] = collection.immutable.Set[A]

  15. type String = java.lang.String

  16. implicit final class StringAdd[A] extends AnyVal

  17. implicit final class StringFormat[A] extends AnyVal

  18. type ClassManifest[T] = ClassTag[T]

    Annotations
    @implicitNotFound( msg = ... ) @deprecated
    Deprecated

    (Since version 2.10.0) Use scala.reflect.ClassTag instead

  19. type Pair[+A, +B] = (A, B)

    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use built-in tuple syntax or Tuple2 instead

  20. type Triple[+A, +B, +C] = (A, B, C)

    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use built-in tuple syntax or Tuple3 instead

Value Members

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

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

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

    Definition Classes
    AnyRef → Any
  4. object =:= extends Serializable

  5. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  6. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  7. def ???: Nothing

    ??? can be used for marking methods that remain to be implemented.

    ??? can be used for marking methods that remain to be implemented.

    Exceptions thrown
    A

    NotImplementedError

  8. implicit def Boolean2boolean(x: java.lang.Boolean): Boolean

  9. implicit def Byte2byte(x: java.lang.Byte): Byte

  10. implicit def Character2char(x: Character): Char

  11. implicit def Double2double(x: java.lang.Double): Double

  12. object DummyImplicit

  13. implicit def Float2float(x: java.lang.Float): Float

  14. implicit def Integer2int(x: Integer): Int

  15. implicit def Long2long(x: java.lang.Long): Long

  16. val Manifest: ManifestFactory.type

  17. val Map: collection.immutable.Map.type

  18. val NoManifest: reflect.NoManifest.type

  19. val Set: collection.immutable.Set.type

  20. implicit def Short2short(x: java.lang.Short): Short

  21. implicit val StringCanBuildFrom: CanBuildFrom[String, Char, String]

  22. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  23. final def assert(assertion: Boolean, message: ⇒ Any): Unit

    Tests an expression, throwing an AssertionError if false.

    Tests an expression, throwing an AssertionError if false. Calls to this method will not be generated if -Xelide-below is at least ASSERTION.

    assertion

    the expression to test

    message

    a String to include in the failure message

    Annotations
    @elidable( level = ASSERTION ) @inline()
    See also

    elidable

  24. def assert(assertion: Boolean): Unit

    Tests an expression, throwing an AssertionError if false.

    Tests an expression, throwing an AssertionError if false. Calls to this method will not be generated if -Xelide-below is at least ASSERTION.

    assertion

    the expression to test

    Annotations
    @elidable( level = ASSERTION )
    See also

    elidable

  25. final def assume(assumption: Boolean, message: ⇒ Any): Unit

    Tests an expression, throwing an AssertionError if false.

    Tests an expression, throwing an AssertionError if false. This method differs from assert only in the intent expressed: assert contains a predicate which needs to be proven, while assume contains an axiom for a static checker. Calls to this method will not be generated if -Xelide-below is at least ASSERTION.

    assumption

    the expression to test

    message

    a String to include in the failure message

    Annotations
    @elidable( level = ASSERTION ) @inline()
    See also

    elidable

  26. def assume(assumption: Boolean): Unit

    Tests an expression, throwing an AssertionError if false.

    Tests an expression, throwing an AssertionError if false. This method differs from assert only in the intent expressed: assert contains a predicate which needs to be proven, while assume contains an axiom for a static checker. Calls to this method will not be generated if -Xelide-below is at least ASSERTION.

    assumption

    the expression to test

    Annotations
    @elidable( level = ASSERTION )
    See also

    elidable

  27. implicit def augmentString(x: String): StringOps

    Annotations
    @inline()
  28. implicit def boolean2Boolean(x: Boolean): java.lang.Boolean

  29. implicit def booleanArrayOps(xs: Array[Boolean]): ArrayOps[Boolean]

  30. implicit def booleanWrapper(x: Boolean): RichBoolean

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  31. implicit def byte2Byte(x: Byte): java.lang.Byte

  32. implicit def byteArrayOps(xs: Array[Byte]): ArrayOps[Byte]

  33. implicit def byteWrapper(x: Byte): RichByte

    We prefer the java.

    We prefer the java.lang.* boxed types to these wrappers in any potential conflicts. Conflicts do exist because the wrappers need to implement ScalaNumber in order to have a symmetric equals method, but that implies implementing java.lang.Number as well.

    Note - these are inlined because they are value classes, but the call to xxxWrapper is not eliminated even though it does nothing. Even inlined, every call site does a no-op retrieval of Predef's MODULE$ because maybe loading Predef has side effects!

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  34. implicit def char2Character(x: Char): Character

  35. implicit def charArrayOps(xs: Array[Char]): ArrayOps[Char]

  36. implicit def charWrapper(c: Char): RichChar

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  37. def classOf[T]: Class[T]

    Retrieve the runtime representation of a class type.

    Retrieve the runtime representation of a class type. classOf[T] is equivalent to the class literal T.class in Java.

    Example:
    1. val listClass = classOf[List[_]]
      // listClass is java.lang.Class[List[_]] = class scala.collection.immutable.List
      
      val mapIntString = classOf[Map[Int,String]]
      // mapIntString is java.lang.Class[Map[Int,String]] = interface scala.collection.immutable.Map
  38. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  39. implicit def conforms[A]: <:<[A, A]

  40. implicit def double2Double(x: Double): java.lang.Double

  41. implicit def doubleArrayOps(xs: Array[Double]): ArrayOps[Double]

  42. implicit def doubleWrapper(x: Double): RichDouble

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  43. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  44. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  45. implicit def fallbackStringCanBuildFrom[T]: CanBuildFrom[String, T, collection.immutable.IndexedSeq[T]]

    Definition Classes
    LowPriorityImplicits
  46. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  47. implicit def float2Float(x: Float): java.lang.Float

  48. implicit def floatArrayOps(xs: Array[Float]): ArrayOps[Float]

  49. implicit def floatWrapper(x: Float): RichFloat

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  50. implicit def genericArrayOps[T](xs: Array[T]): ArrayOps[T]

  51. implicit def genericWrapArray[T](xs: Array[T]): WrappedArray[T]

    Definition Classes
    LowPriorityImplicits
  52. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  53. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  54. def identity[A](x: A): A

  55. def implicitly[T](implicit e: T): T

    Annotations
    @inline()
  56. implicit def int2Integer(x: Int): Integer

  57. implicit def intArrayOps(xs: Array[Int]): ArrayOps[Int]

  58. implicit def intWrapper(x: Int): RichInt

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  59. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  60. def locally[T](x: T): T

    Annotations
    @inline()
  61. implicit def long2Long(x: Long): java.lang.Long

  62. implicit def longArrayOps(xs: Array[Long]): ArrayOps[Long]

  63. implicit def longWrapper(x: Long): RichLong

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  64. def manifest[T](implicit m: Manifest[T]): Manifest[T]

  65. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  66. final def notify(): Unit

    Definition Classes
    AnyRef
  67. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  68. def optManifest[T](implicit m: OptManifest[T]): OptManifest[T]

  69. def print(x: Any): Unit

  70. def printf(text: String, xs: Any*): Unit

  71. def println(x: Any): Unit

  72. def println(): Unit

  73. implicit def refArrayOps[T <: AnyRef](xs: Array[T]): ArrayOps[T]

  74. final def require(requirement: Boolean, message: ⇒ Any): Unit

    Tests an expression, throwing an IllegalArgumentException if false.

    Tests an expression, throwing an IllegalArgumentException if false. This method is similar to assert, but blames the caller of the method for violating the condition.

    requirement

    the expression to test

    message

    a String to include in the failure message

    Annotations
    @inline()
  75. def require(requirement: Boolean): Unit

    Tests an expression, throwing an IllegalArgumentException if false.

    Tests an expression, throwing an IllegalArgumentException if false. This method is similar to assert, but blames the caller of the method for violating the condition.

    requirement

    the expression to test

  76. implicit def short2Short(x: Short): java.lang.Short

  77. implicit def shortArrayOps(xs: Array[Short]): ArrayOps[Short]

  78. implicit def shortWrapper(x: Short): RichShort

    Definition Classes
    LowPriorityImplicits
    Annotations
    @inline()
  79. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  80. def toString(): java.lang.String

    Definition Classes
    AnyRef → Any
  81. implicit def tuple2ToZippedOps[T1, T2](x: (T1, T2)): Ops[T1, T2]

  82. implicit def tuple3ToZippedOps[T1, T2, T3](x: (T1, T2, T3)): Ops[T1, T2, T3]

  83. implicit def unaugmentString(x: StringOps): String

    Annotations
    @inline()
  84. implicit def unitArrayOps(xs: Array[Unit]): ArrayOps[Unit]

  85. implicit def unwrapString(ws: WrappedString): String

    Definition Classes
    LowPriorityImplicits
  86. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  87. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  88. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  89. implicit def wrapBooleanArray(xs: Array[Boolean]): WrappedArray[Boolean]

    Definition Classes
    LowPriorityImplicits
  90. implicit def wrapByteArray(xs: Array[Byte]): WrappedArray[Byte]

    Definition Classes
    LowPriorityImplicits
  91. implicit def wrapCharArray(xs: Array[Char]): WrappedArray[Char]

    Definition Classes
    LowPriorityImplicits
  92. implicit def wrapDoubleArray(xs: Array[Double]): WrappedArray[Double]

    Definition Classes
    LowPriorityImplicits
  93. implicit def wrapFloatArray(xs: Array[Float]): WrappedArray[Float]

    Definition Classes
    LowPriorityImplicits
  94. implicit def wrapIntArray(xs: Array[Int]): WrappedArray[Int]

    Definition Classes
    LowPriorityImplicits
  95. implicit def wrapLongArray(xs: Array[Long]): WrappedArray[Long]

    Definition Classes
    LowPriorityImplicits
  96. implicit def wrapRefArray[T <: AnyRef](xs: Array[T]): WrappedArray[T]

    Definition Classes
    LowPriorityImplicits
  97. implicit def wrapShortArray(xs: Array[Short]): WrappedArray[Short]

    Definition Classes
    LowPriorityImplicits
  98. implicit def wrapString(s: String): WrappedString

    Definition Classes
    LowPriorityImplicits
  99. implicit def wrapUnitArray(xs: Array[Unit]): WrappedArray[Unit]

    Definition Classes
    LowPriorityImplicits

Deprecated Value Members

  1. val ClassManifest: ClassManifestFactory.type

    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use scala.reflect.ClassTag instead

  2. object Pair

    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use built-in tuple syntax or Tuple2 instead

  3. object Triple

    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use built-in tuple syntax or Tuple3 instead

  4. def any2ArrowAssoc[A](x: A): ArrowAssoc[A]

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use ArrowAssoc

  5. def any2Ensuring[A](x: A): Ensuring[A]

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use Ensuring

  6. def any2stringadd(x: Any): StringAdd[Any]

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use String interpolation

  7. def any2stringfmt(x: Any): StringFormat[Any]

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use StringFormat

  8. def arrayToCharSequence(xs: Array[Char]): CharSequence

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use ArrayCharSequence

  9. def classManifest[T](implicit m: ClassManifest[T]): ClassManifest[T]

    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use scala.reflect.classTag[T] instead

  10. def error(message: String): Nothing

    Annotations
    @deprecated
    Deprecated

    (Since version 2.9.0) Use sys.error(message) instead

  11. def exceptionWrapper(exc: scala.Throwable): RichException

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use Throwable directly

  12. def readBoolean(): Boolean

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  13. def readByte(): Byte

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  14. def readChar(): Char

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  15. def readDouble(): Double

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  16. def readFloat(): Float

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  17. def readInt(): Int

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  18. def readLine(text: String, args: Any*): String

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  19. def readLine(): String

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  20. def readLong(): Long

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  21. def readShort(): Short

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  22. def readf(format: String): List[Any]

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  23. def readf1(format: String): Any

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  24. def readf2(format: String): (Any, Any)

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  25. def readf3(format: String): (Any, Any, Any)

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use the method in scala.io.ReadStdin

  26. def seqToCharSequence(xs: collection.IndexedSeq[Char]): CharSequence

    Definition Classes
    DeprecatedPredef
    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use SeqCharSequence

Inherited from DeprecatedPredef

Inherited from LowPriorityImplicits

Inherited from AnyRef

Inherited from Any

Ungrouped