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:

    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
    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 https://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 words = Files.readAllLines("/etc/dictionaries-common/words").asScala
      words.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 jdk

    The jdk package contains utilities to interact with JDK classes.

    The jdk package contains utilities to interact with JDK classes.

    This packages offers a number of converters, that are able to wrap or copy types from the scala library to equivalent types in the JDK class library and vice versa:

    By convention, converters that wrap an object to provide a different interface to the same underlying data structure use .asScala and .asJava extension methods, whereas converters that copy the underlying data structure use .toScala and .toJava.

    In the javaapi package, the same converters can be found with a java-friendly interface that don't rely on implicit enrichments.

    Additionally, this package offers Accumulators, capable of efficiently traversing JDK Streams.

    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 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
  • package process
  • BooleanProp
  • Prop
  • ShutdownHookThread
  • SystemProperties
  • package util
    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.

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

Package Members

  1. package process

Type Members

  1. trait BooleanProp extends Prop[Boolean]

    A few additional conveniences for Boolean properties.

  2. trait Prop[+T] extends AnyRef

    A lightweight interface wrapping a property contained in some unspecified map.

    A lightweight interface wrapping a property contained in some unspecified map. Generally it'll be the system properties but this is not a requirement.

    See scala.sys.SystemProperties for an example usage.

  3. class ShutdownHookThread extends Thread

    A minimal Thread wrapper to enhance shutdown hooks.

    A minimal Thread wrapper to enhance shutdown hooks. It knows how to unregister itself.

  4. class SystemProperties extends AbstractMap[String, String]

    A bidirectional map wrapping the java System properties.

    A bidirectional map wrapping the java System properties. Changes to System properties will be immediately visible in the map, and modifications made to the map will be immediately applied to the System properties. If a security manager is in place which prevents the properties from being read or written, the AccessControlException will be caught and discarded.

Value Members

  1. def addShutdownHook(body: => Unit): ShutdownHookThread

    Register a shutdown hook to be run when the VM exits.

    Register a shutdown hook to be run when the VM exits. The hook is automatically registered: the returned value can be ignored, but is available in case the Thread requires further modification. It can also be unregistered by calling ShutdownHookThread#remove().

    Note that shutdown hooks are NOT guaranteed to be run.

    body

    the body of code to run at shutdown

    returns

    the Thread which will run the shutdown hook.

    See also

    scala.sys.ShutdownHookThread

  2. def allThreads(): IndexedSeq[Thread]

    Returns all active thread in the current thread's thread group and subgroups.

    Returns all active thread in the current thread's thread group and subgroups.

    returns

    an IndexedSeq containing the threads.

  3. def env: Map[String, String]

    An immutable Map representing the current system environment.

    An immutable Map representing the current system environment.

    If lookup fails, use System.getenv(_) for case-insensitive lookup on a certain platform. If that also fails, throw NoSuchElementException.

    returns

    a Map containing the system environment variables.

  4. def error(message: String): Nothing

    Throw a new RuntimeException with the supplied message.

    Throw a new RuntimeException with the supplied message.

    returns

    Nothing.

  5. def exit(status: Int): Nothing

    Exit the JVM with the given status code.

    Exit the JVM with the given status code.

    returns

    Nothing.

  6. def exit(): Nothing

    Exit the JVM with the default status code.

    Exit the JVM with the default status code.

    returns

    Nothing.

  7. def props: SystemProperties

    A bidirectional, mutable Map representing the current system Properties.

    A bidirectional, mutable Map representing the current system Properties.

    returns

    a SystemProperties.

    See also

    scala.sys.SystemProperties

  8. def runtime: Runtime

    A convenience method to get the current Runtime instance.

    A convenience method to get the current Runtime instance.

    returns

    the result of java.lang.Runtime.getRuntime()

  9. object BooleanProp
  10. object Prop
  11. object ShutdownHookThread
  12. object SystemProperties

    The values in SystemProperties can be used to access and manipulate designated system properties.

    The values in SystemProperties can be used to access and manipulate designated system properties. See scala.sys.Prop for particulars.

    Example:
    1. if (!headless.isSet) headless.enable()

Inherited from AnyRef

Inherited from Any

Ungrouped