An instance of A <:< B
witnesses that A
is a subtype of B
.
An instance of A =:= B
witnesses that the types A
and B
are equal.
A type for which there is always an implicit value.
(Since version 2.10.0) Use scala.reflect.ClassTag
instead
???
can be used for marking methods that remain to be implemented.
???
can be used for marking methods that remain to be implemented.
NotImplementedError
Tests an expression, throwing an AssertionError
if false.
Tests an expression, throwing an AssertionError
if false.
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
.
the expression to test
a String to include in the failure message
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
.
the expression to test
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!
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.
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
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.
the expression to test
a String to include in the failure message
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.
the expression to test
(Since version 2.10.0) Use scala.reflect.ClassTag
instead
(Since version 2.11.0) Use ArrowAssoc
(Since version 2.11.0) Use Ensuring
(Since version 2.11.0) Use String interpolation
(Since version 2.11.0) Use StringFormat
(Since version 2.11.0) Use ArrayCharSequence
(Since version 2.10.0) Use scala.reflect.classTag[T] instead
(Since version 2.9.0) Use sys.error(message)
instead
(Since version 2.11.0) Use Throwable
directly
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use the method in scala.io.ReadStdin
(Since version 2.11.0) Use SeqCharSequence
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). The types
Pair
(a scala.Tuple2) andTriple
(a scala.Tuple3), with simple constructors, are also provided.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 thescala
command.Variants of
assert
intended for use with static analysis tools are also provided:assume
,require
andensuring
.require
andensuring
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,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 fromassert
in that if the condition fails, then the caller of the function is to blame rather than a logical error having been made withinaddNaturals
itself.ensures
is a form ofassert
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.