Packages

  • package root

    This is the documentation for the Scala standard library.

    This is the documentation for the Scala standard library.

    Package structure

    The scala package contains core types like Int, Float, Array or Option which are accessible in all Scala compilation units without explicit qualification or imports.

    Notable packages include:

    Other packages exist. See the complete list on the right.

    Additional parts of the standard library are shipped as separate libraries. These include:

    • scala.reflect - Scala's reflection API (scala-reflect.jar)
    • scala.xml - XML parsing, manipulation, and serialization (scala-xml.jar)
    • scala.collection.parallel - Parallel collections (scala-parallel-collections.jar)
    • scala.util.parsing - Parser combinators (scala-parser-combinators.jar)
    • scala.swing - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)

    Automatic imports

    Identifiers in the scala package and the scala.Predef object are always in scope by default.

    Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example, List is an alias for scala.collection.immutable.List.

    Other aliases refer to classes provided by the underlying platform. For example, on the JVM, String is an alias for java.lang.String.

    Definition Classes
    root
  • package scala

    Core Scala types.

    Core Scala types. They are always available without an explicit import.

    Definition Classes
    root
  • package annotation
    Definition Classes
    scala
  • package beans
    Definition Classes
    scala
  • package collection

    Contains the base traits and objects needed to use and extend Scala's collection library.

    Contains the base traits and objects needed to use and extend Scala's collection library.

    Guide

    A detailed guide for using the collections library is available at http://docs.scala-lang.org/overviews/collections/introduction.html. Developers looking to extend the collections library can find a description of its architecture at http://docs.scala-lang.org/overviews/core/architecture-of-scala-collections.html.

    Using Collections

    It is convenient to treat all collections as either a scala.collection.Traversable or scala.collection.Iterable, as these traits define the vast majority of operations on a collection.

    Collections can, of course, be treated as specifically as needed, and the library is designed to ensure that the methods that transform collections will return a collection of the same type:

    scala> val array = Array(1,2,3,4,5,6)
    array: Array[Int] = Array(1, 2, 3, 4, 5, 6)
    
    scala> array map { _.toString }
    res0: Array[String] = Array(1, 2, 3, 4, 5, 6)
    
    scala> val list = List(1,2,3,4,5,6)
    list: List[Int] = List(1, 2, 3, 4, 5, 6)
    
    scala> list map { _.toString }
    res1: List[String] = List(1, 2, 3, 4, 5, 6)

    Creating Collections

    The most common way to create a collection is to use its companion object as a factory. The three most commonly used collections are scala.collection.Seq, scala.collection.immutable.Set, and scala.collection.immutable.Map. They can be used directly as shown below since their companion objects are all available as type aliases in either the scala package or in scala.Predef. New collections are created like this:

    scala> val seq = Seq(1,2,3,4,1)
    seq: Seq[Int] = List(1, 2, 3, 4, 1)
    
    scala> val set = Set(1,2,3,4,1)
    set: scala.collection.immutable.Set[Int] = Set(1, 2, 3, 4)
    
    scala> val map = Map(1 -> "one", 2 -> "two", 3 -> "three", 2 -> "too")
    map: scala.collection.immutable.Map[Int,String] = Map(1 -> one, 2 -> too, 3 -> three)

    It is also typical to prefer the scala.collection.immutable collections over those in scala.collection.mutable; the types aliased in the scala.Predef object are the immutable versions.

    Also note that the collections library was carefully designed to include several implementations of each of the three basic collection types. These implementations have specific performance characteristics which are described in the guide.

    The concrete parallel collections also have specific performance characteristics which are described in the parallel collections guide

    Converting to and from Java Collections

    The scala.collection.JavaConverters object provides a collection of decorators that allow converting between Scala and Java collections using asScala and asJava methods.

    Definition Classes
    scala
  • package compat
    Definition Classes
    scala
  • package concurrent

    This package object contains primitives for concurrent and parallel programming.

    This package object contains primitives for concurrent and parallel programming.

    Guide

    A more detailed guide to Futures and Promises, including discussion and examples can be found at http://docs.scala-lang.org/overviews/core/futures.html.

    Common Imports

    When working with Futures, you will often find that importing the whole concurrent package is convenient:

    import scala.concurrent._

    When using things like Futures, it is often required to have an implicit ExecutionContext in scope. The general advice for these implicits are as follows.

    If the code in question is a class or method definition, and no ExecutionContext is available, request one from the caller by adding an implicit parameter list:

    def myMethod(myParam: MyType)(implicit ec: ExecutionContext) = …
    //Or
    class MyClass(myParam: MyType)(implicit ec: ExecutionContext) { … }

    This allows the caller of the method, or creator of the instance of the class, to decide which ExecutionContext should be used.

    For typical REPL usage and experimentation, importing the global ExecutionContext is often desired.

    import scala.concurrent.ExcutionContext.Implicits.global

    Specifying Durations

    Operations often require a duration to be specified. A duration DSL is available to make defining these easier:

    import scala.concurrent.duration._
    val d: Duration = 10.seconds

    Using Futures For Non-blocking Computation

    Basic use of futures is easy with the factory method on Future, which executes a provided function asynchronously, handing you back a future result of that function without blocking the current thread. In order to create the Future you will need either an implicit or explicit ExecutionContext to be provided:

    import scala.concurrent._
    import ExecutionContext.Implicits.global  // implicit execution context
    
    val firstZebra: Future[Int] = Future {
      val source = scala.io.Source.fromFile("/etc/dictionaries-common/words")
      source.toSeq.indexOfSlice("zebra")
    }

    Avoid Blocking

    Although blocking is possible in order to await results (with a mandatory timeout duration):

    import scala.concurrent.duration._
    Await.result(firstZebra, 10.seconds)

    and although this is sometimes necessary to do, in particular for testing purposes, blocking in general is discouraged when working with Futures and concurrency in order to avoid potential deadlocks and improve performance. Instead, use callbacks or combinators to remain in the future domain:

    val animalRange: Future[Int] = for {
      aardvark <- firstAardvark
      zebra <- firstZebra
    } yield zebra - aardvark
    
    animalRange.onSuccess {
      case x if x > 500000 => println("It's a long way from Aardvark to Zebra")
    }
    Definition Classes
    scala
  • package io
    Definition Classes
    scala
  • package math

    The package object scala.math contains methods for performing basic numeric operations such as elementary exponential, logarithmic, root and trigonometric functions.

    The package object scala.math contains methods for performing basic numeric operations such as elementary exponential, logarithmic, root and trigonometric functions.

    All methods forward to java.lang.Math unless otherwise noted.

    Definition Classes
    scala
    See also

    java.lang.Math

  • package ref
    Definition Classes
    scala
  • package reflect
    Definition Classes
    scala
  • package runtime
    Definition Classes
    scala
  • AbstractFunction0
  • AbstractFunction1
  • AbstractFunction10
  • AbstractFunction11
  • AbstractFunction12
  • AbstractFunction13
  • AbstractFunction14
  • AbstractFunction15
  • AbstractFunction16
  • AbstractFunction17
  • AbstractFunction18
  • AbstractFunction19
  • AbstractFunction2
  • AbstractFunction20
  • AbstractFunction21
  • AbstractFunction22
  • AbstractFunction3
  • AbstractFunction4
  • AbstractFunction5
  • AbstractFunction6
  • AbstractFunction7
  • AbstractFunction8
  • AbstractFunction9
  • AbstractPartialFunction
  • ArrayCharSequence
  • FractionalProxy
  • IntegralProxy
  • LambdaDeserializer
  • LazyBoolean
  • LazyByte
  • LazyChar
  • LazyDouble
  • LazyFloat
  • LazyInt
  • LazyLong
  • LazyRef
  • LazyShort
  • LazyUnit
  • NonLocalReturnControl
  • OrderedProxy
  • RangedProxy
  • RichBoolean
  • RichByte
  • RichChar
  • RichDouble
  • RichFloat
  • RichInt
  • RichLong
  • RichShort
  • ScalaNumberProxy
  • ScalaWholeNumberProxy
  • Tuple2Zipped
  • Tuple3Zipped
  • ZippedTraversable2
  • ZippedTraversable3
  • package sys

    The package object scala.sys contains methods for reading and altering core aspects of the virtual machine as well as the world outside of it.

    The package object scala.sys contains methods for reading and altering core aspects of the virtual machine as well as the world outside of it.

    Definition Classes
    scala
    Version

    2.9

    Since

    2.9

  • package util
    Definition Classes
    scala
p

scala

runtime

package runtime

Source
package.scala
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. runtime
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AbstractFunction0[+R] extends () ⇒ R
  2. abstract class AbstractFunction1[-T1, +R] extends (T1) ⇒ R
  3. abstract class AbstractFunction10[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) ⇒ R
  4. abstract class AbstractFunction11[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) ⇒ R
  5. abstract class AbstractFunction12[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) ⇒ R
  6. abstract class AbstractFunction13[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) ⇒ R
  7. abstract class AbstractFunction14[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) ⇒ R
  8. abstract class AbstractFunction15[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) ⇒ R
  9. abstract class AbstractFunction16[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) ⇒ R
  10. abstract class AbstractFunction17[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) ⇒ R
  11. abstract class AbstractFunction18[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) ⇒ R
  12. abstract class AbstractFunction19[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) ⇒ R
  13. abstract class AbstractFunction2[-T1, -T2, +R] extends (T1, T2) ⇒ R
  14. abstract class AbstractFunction20[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) ⇒ R
  15. abstract class AbstractFunction21[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) ⇒ R
  16. abstract class AbstractFunction22[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, -T10, -T11, -T12, -T13, -T14, -T15, -T16, -T17, -T18, -T19, -T20, -T21, -T22, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) ⇒ R
  17. abstract class AbstractFunction3[-T1, -T2, -T3, +R] extends (T1, T2, T3) ⇒ R
  18. abstract class AbstractFunction4[-T1, -T2, -T3, -T4, +R] extends (T1, T2, T3, T4) ⇒ R
  19. abstract class AbstractFunction5[-T1, -T2, -T3, -T4, -T5, +R] extends (T1, T2, T3, T4, T5) ⇒ R
  20. abstract class AbstractFunction6[-T1, -T2, -T3, -T4, -T5, -T6, +R] extends (T1, T2, T3, T4, T5, T6) ⇒ R
  21. abstract class AbstractFunction7[-T1, -T2, -T3, -T4, -T5, -T6, -T7, +R] extends (T1, T2, T3, T4, T5, T6, T7) ⇒ R
  22. abstract class AbstractFunction8[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8) ⇒ R
  23. abstract class AbstractFunction9[-T1, -T2, -T3, -T4, -T5, -T6, -T7, -T8, -T9, +R] extends (T1, T2, T3, T4, T5, T6, T7, T8, T9) ⇒ R
  24. abstract class AbstractPartialFunction[-T1, +R] extends (T1) ⇒ R with PartialFunction[T1, R]

    AbstractPartialFunction reformulates all operations of its supertrait PartialFunction in terms of isDefinedAt and applyOrElse.

    AbstractPartialFunction reformulates all operations of its supertrait PartialFunction in terms of isDefinedAt and applyOrElse.

    This allows more efficient implementations in many cases:

    • optimized orElse method supports chained orElse in linear time, and with no slow-down if the orElse part is not needed.
    • optimized lift method helps to avoid double evaluation of pattern matchers & guards of partial function literals.

    This trait is used as a basis for implementation of all partial function literals.

    Since

    2.10

  25. final class ArrayCharSequence extends CharSequence
  26. trait FractionalProxy[T] extends ScalaNumberProxy[T] with RangedProxy[T]
  27. trait IntegralProxy[T] extends ScalaWholeNumberProxy[T] with RangedProxy[T]
  28. class LazyBoolean extends Serializable
    Annotations
    @SerialVersionUID()
  29. class LazyByte extends Serializable
    Annotations
    @SerialVersionUID()
  30. class LazyChar extends Serializable
    Annotations
    @SerialVersionUID()
  31. class LazyDouble extends Serializable
    Annotations
    @SerialVersionUID()
  32. class LazyFloat extends Serializable
    Annotations
    @SerialVersionUID()
  33. class LazyInt extends Serializable
    Annotations
    @SerialVersionUID()
  34. class LazyLong extends Serializable
    Annotations
    @SerialVersionUID()
  35. class LazyRef[T] extends Serializable

    Classes used as holders for lazy vals defined in methods.

    Classes used as holders for lazy vals defined in methods.

    Annotations
    @SerialVersionUID()
  36. class LazyShort extends Serializable
    Annotations
    @SerialVersionUID()
  37. class LazyUnit extends Serializable
    Annotations
    @SerialVersionUID()
  38. class NonLocalReturnControl[T] extends Throwable with ControlThrowable
  39. trait OrderedProxy[T] extends Ordered[T] with Typed[T]
  40. trait RangedProxy[T] extends Typed[T]
  41. final class RichBoolean extends AnyVal with OrderedProxy[Boolean]
  42. final class RichByte extends AnyVal with ScalaWholeNumberProxy[Byte]
  43. final class RichChar extends AnyVal with IntegralProxy[Char]
  44. final class RichDouble extends AnyVal with FractionalProxy[Double]
  45. final class RichFloat extends AnyVal with FractionalProxy[Float]
  46. final class RichInt extends AnyVal with ScalaNumberProxy[Int] with RangedProxy[Int]
  47. final class RichLong extends AnyVal with IntegralProxy[Long]
  48. final class RichShort extends AnyVal with ScalaWholeNumberProxy[Short]
  49. trait ScalaNumberProxy[T] extends ScalaNumericAnyConversions with Typed[T] with OrderedProxy[T]

    Base classes for the Rich* wrappers of the primitive types.

    Base classes for the Rich* wrappers of the primitive types. As with all classes in scala.runtime.*, this is not a supported API.

    Version

    2.9

    Since

    2.9

  50. trait ScalaWholeNumberProxy[T] extends ScalaNumberProxy[T]
  51. final class Tuple2Zipped[El1, Repr1, El2, Repr2] extends AnyVal with ZippedTraversable2[El1, El2]
  52. final class Tuple3Zipped[El1, Repr1, El2, Repr2, El3, Repr3] extends AnyVal with ZippedTraversable3[El1, El2, El3]
  53. trait ZippedTraversable2[+El1, +El2] extends Any

    This interface is intended as a minimal interface, not complicated by the requirement to resolve type constructors, for implicit search (which only needs to find an implicit conversion to Traversable for our purposes.)

  54. trait ZippedTraversable3[+El1, +El2, +El3] extends Any

    See comment on ZippedTraversable2

Value Members

  1. object LambdaDeserializer

    This class is only intended to be called by synthetic $deserializeLambda$ method that the Scala 2.12 compiler will add to classes hosting lambdas.

    This class is only intended to be called by synthetic $deserializeLambda$ method that the Scala 2.12 compiler will add to classes hosting lambdas.

    It is not intended to be consumed directly.

  2. object Tuple2Zipped
  3. object Tuple3Zipped
  4. object ZippedTraversable2
  5. object ZippedTraversable3

Inherited from AnyRef

Inherited from Any

Ungrouped