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.swing - A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)
    • scala.util.parsing - Parser combinators, including an example implementation of a JSON parser (scala-parser-combinators.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, furthermore you are likely to need an implicit ExecutionContext in scope for many operations involving Futures and Promises:

    import scala.concurrent._
    import ExecutionContext.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
  • AnyValManifest
  • ClassManifestDeprecatedApis
  • ClassManifestFactory
  • ClassTag
  • Manifest
  • ManifestFactory
  • NameTransformer
  • NoManifest
  • OptManifest
  • package runtime
    Definition Classes
    scala
  • 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 text
    Definition Classes
    scala
  • package util
    Definition Classes
    scala
p

scala

reflect

package reflect

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. reflect
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. abstract class AnyValManifest [T <: AnyVal] extends Manifest[T] with Equals
    Annotations
    @SerialVersionUID()
  2. trait ClassTag [T] extends ClassManifestDeprecatedApis[T] with Equals with Serializable

    A ClassTag[T] stores the erased class of a given type T, accessible via the runtimeClass field.

    A ClassTag[T] stores the erased class of a given type T, accessible via the runtimeClass field. This is particularly useful for instantiating Arrays whose element types are unknown at compile time.

    ClassTags are a weaker special case of scala.reflect.api.TypeTags#TypeTags, in that they wrap only the runtime class of a given type, whereas a TypeTag contains all static type information. That is, ClassTags are constructed from knowing only the top-level class of a type, without necessarily knowing all of its argument types. This runtime information is enough for runtime Array creation.

    For example:

    scala> def mkArray[T : ClassTag](elems: T*) = Array[T](elems: _*)
    mkArray: [T](elems: T*)(implicit evidence$1: scala.reflect.ClassTag[T])Array[T]
    
    scala> mkArray(42, 13)
    res0: Array[Int] = Array(42, 13)
    
    scala> mkArray("Japan","Brazil","Germany")
    res1: Array[String] = Array(Japan, Brazil, Germany)

    See scala.reflect.api.TypeTags for more examples, or the Reflection Guide: TypeTags for more details.

    Annotations
    @implicitNotFound( msg = "No ClassTag available for ${T}" )
  3. trait Manifest [T] extends ClassManifest[T] with Equals

    A Manifest[T] is an opaque descriptor for type T.

    A Manifest[T] is an opaque descriptor for type T. Its supported use is to give access to the erasure of the type as a Class instance, as is necessary for the creation of native Arrays if the class is not known at compile time.

    The type-relation operators <:< and =:= should be considered approximations only, as there are numerous aspects of type conformance which are not yet adequately represented in manifests.

    Example usages:

    def arr[T] = new Array[T](0)                          // does not compile
    def arr[T](implicit m: Manifest[T]) = new Array[T](0) // compiles
    def arr[T: Manifest] = new Array[T](0)                // shorthand for the preceding
    
    // Methods manifest, classManifest, and optManifest are in [[scala.Predef]].
    def isApproxSubType[T: Manifest, U: Manifest] = manifest[T] <:< manifest[U]
    isApproxSubType[List[String], List[AnyRef]] // true
    isApproxSubType[List[String], List[Int]]    // false
    
    def methods[T: ClassManifest] = classManifest[T].erasure.getMethods
    def retType[T: ClassManifest](name: String) =
      methods[T] find (_.getName == name) map (_.getGenericReturnType)
    
    retType[Map[_, _]]("values")  // Some(scala.collection.Iterable)
    Annotations
    @implicitNotFound( msg = "No Manifest available for ${T}." )
  4. trait OptManifest [+T] extends Serializable

    A OptManifest[T] is an optional scala.reflect.Manifest.

    A OptManifest[T] is an optional scala.reflect.Manifest.

    It is either a Manifest or the value NoManifest.

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

    A ClassManifest[T] is an opaque descriptor for type T.

    A ClassManifest[T] is an opaque descriptor for type T. It is used by the compiler to preserve information necessary for instantiating Arrays in those cases where the element type is unknown at compile time.

    The type-relation operators make an effort to present a more accurate picture than can be realized with erased types, but they should not be relied upon to give correct answers. In particular they are likely to be wrong when variance is involved or when a subtype has a different number of type arguments than a supertype.

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

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

  6. trait ClassManifestDeprecatedApis [T] extends OptManifest[T]
    Annotations
    @deprecated
    Deprecated

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

Value Members

  1. val Manifest: ManifestFactory.type

    The object Manifest defines factory methods for manifests.

    The object Manifest defines factory methods for manifests. It is intended for use by the compiler and should not be used in client code.

  2. def classTag[T](implicit ctag: ClassTag[T]): ClassTag[T]
  3. def ensureAccessible[T <: AccessibleObject](m: T): T

    Make a java reflection object accessible, if it is not already and it is possible to do so.

    Make a java reflection object accessible, if it is not already and it is possible to do so. If a SecurityException is thrown in the attempt, it is caught and discarded.

  4. object ClassManifestFactory

    ClassManifestFactory defines factory methods for manifests.

    ClassManifestFactory defines factory methods for manifests. It is intended for use by the compiler and should not be used in client code.

    Unlike ClassManifest, this factory isn't annotated with a deprecation warning. This is done to prevent avalanches of deprecation warnings in the code that calls methods with manifests.

    In a perfect world, we would just remove the @deprecated annotation from ClassManifest the object and then delete it in 2.11. After all, that object is explicitly marked as internal, so no one should use it. However a lot of existing libraries disregarded the Scaladoc that comes with ClassManifest, so we need to somehow nudge them into migrating prior to removing stuff out of the blue. Hence we've introduced this design decision as the lesser of two evils.

  5. object ClassTag extends Serializable

    Class tags corresponding to primitive types and constructor/extractor for ClassTags.

  6. object ManifestFactory

    ManifestFactory defines factory methods for manifests.

    ManifestFactory defines factory methods for manifests. It is intended for use by the compiler and should not be used in client code.

    Unlike Manifest, this factory isn't annotated with a deprecation warning. This is done to prevent avalanches of deprecation warnings in the code that calls methods with manifests. Why so complicated? Read up the comments for ClassManifestFactory.

  7. object NameTransformer

    Provides functions to encode and decode Scala symbolic names.

    Provides functions to encode and decode Scala symbolic names. Also provides some constants.

  8. object NoManifest extends OptManifest[Nothing] with Serializable

    One of the branches of an scala.reflect.OptManifest.

Deprecated Value Members

  1. val ClassManifest: ClassManifestFactory.type

    The object ClassManifest defines factory methods for manifests.

    The object ClassManifest defines factory methods for manifests. It is intended for use by the compiler and should not be used in client code.

    Annotations
    @deprecated
    Deprecated

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

Inherited from AnyRef

Inherited from Any

Ungrouped