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
(Since version 2.10.0) Use scala.reflect.ClassTag (to capture erasures) or scala.reflect.runtime.universe.TypeTag (to capture types) or both instead
(Since version 2.10.0) This notion doesn't have a corresponding concept in 2.10, because scala.reflect.runtime.universe.TypeTag can capture arbitrary types. Use type tags instead of manifests, and there will be no need in opt manifests.
Test two objects for inequality.
Test two objects for inequality.
true if !(this == that), false otherwise.
Equivalent to x.hashCode except for boxed numeric types and null.
Equivalent to x.hashCode except for boxed numeric types and null.
For numerics, it returns a hash value which is consistent
with value equality: if two value type instances compare
as true, then ## will produce the same hash value for each
of them.
For null returns a hashcode where null.hashCode throws a
NullPointerException.
a hash value consistent with ==
Test two objects for equality.
Test two objects for equality.
The expression x == that is equivalent to if (x eq null) that eq null else x.equals(that).
true if the receiver object is equivalent to the argument; false otherwise.
??? can be used for marking methods that remain to be implemented.
??? can be used for marking methods that remain to be implemented.
NotImplementedError
Cast the receiver object to be of type T0.
Cast the receiver object to be of type T0.
Note that the success of a cast at runtime is modulo Scala's erasure semantics.
Therefore the expression 1.asInstanceOf[String] will throw a ClassCastException at
runtime, while the expression List(1).asInstanceOf[List[String]] will not.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the requested type.
the receiver object.
if the receiver object is not an instance of the erasure of type T0.
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.
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
Create a copy of the receiver object.
Tests whether the argument (arg0) is a reference to the receiver object (this).
Tests whether the argument (arg0) is a reference to the receiver object (this).
The eq method implements an equivalence relation on
non-null instances of AnyRef, and has three additional properties:
x and y of type AnyRef, multiple invocations of
x.eq(y) consistently returns true or consistently returns false.x of type AnyRef, x.eq(null) and null.eq(x) returns false.null.eq(null) returns true. When overriding the equals or hashCode methods, it is important to ensure that their behavior is
consistent with reference equality. Therefore, if two objects are references to each other (o1 eq o2), they
should be equal to each other (o1 == o2) and they should hash to the same value (o1.hashCode == o2.hashCode).
true if the argument is a reference to the receiver object; false otherwise.
The equality method for reference types.
Called by the garbage collector on the receiver object when there are no more references to the object.
Called by the garbage collector on the receiver object when there are no more references to the object.
The details of when and if the finalize method is invoked, as
well as the interaction between finalize and non-local returns
and exceptions, are all platform dependent.
A representation that corresponds to the dynamic class of the receiver object.
A representation that corresponds to the dynamic class of the receiver object.
The nature of the representation is platform dependent.
a representation that corresponds to the dynamic class of the receiver object.
not specified by SLS as a member of AnyRef
The hashCode method for reference types.
Test whether the dynamic type of the receiver object is T0.
Test whether the dynamic type of the receiver object is T0.
Note that the result of the test is modulo Scala's erasure semantics.
Therefore the expression 1.isInstanceOf[String] will return false, while the
expression List(1).isInstanceOf[List[String]] will return true.
In the latter example, because the type argument is erased as part of compilation it is
not possible to check whether the contents of the list are of the specified type.
true if the receiver object is an instance of erasure of type T0; false otherwise.
Equivalent to !(this eq that).
Equivalent to !(this eq that).
true if the argument is not a reference to the receiver object; false otherwise.
Wakes up a single thread that is waiting on the receiver object's monitor.
Wakes up a single thread that is waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
Wakes up all threads that are waiting on the receiver object's monitor.
Wakes up all threads that are waiting on the receiver object's monitor.
not specified by SLS as a member of AnyRef
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
Creates a String representation of this object.
Creates a String representation of this object. The default representation is platform dependent. On the java platform it is the concatenation of the class name, "@", and the object's hashcode in hexadecimal.
a String representation of the object.
(Since version 2.10.0) Use scala.reflect.ClassTag instead
(Since version 2.10.0) Use scala.reflect.ClassTag (to capture erasures) or scala.reflect.runtime.universe.TypeTag (to capture types) or both instead
(Since version 2.10.0) This notion doesn't have a corresponding concept in 2.10, because scala.reflect.runtime.universe.TypeTag can capture arbitrary types. Use type tags instead of manifests, and there will be no need in opt manifests.
(Since version 2.10.0) Use .toDouble for explicit conversion and Byte.byte2double for implicit conversion
(Since version 2.10.0) Use .toFloat for explicit conversion and Byte.byte2float for implicit conversion
(Since version 2.10.0) Use .toInt for explicit conversion and Byte.byte2int for implicit conversion
(Since version 2.10.0) Use .toLong for explicit conversion and Byte.byte2long for implicit conversion
(Since version 2.10.0) Use .toShort for explicit conversion and Byte.byte2short for implicit conversion
(Since version 2.10.0) Use .toDouble for explicit conversion and Char.char2double for implicit conversion
(Since version 2.10.0) Use .toFloat for explicit conversion and Char.char2float for implicit conversion
(Since version 2.10.0) Use .toInt for explicit conversion and Char.char2int for implicit conversion
(Since version 2.10.0) Use .toLong for explicit conversion and Char.char2long for implicit conversion
(Since version 2.9.0) Use sys.error(message) instead
(Since version 2.9.0) Use sys.exit(status) instead
(Since version 2.9.0) Use sys.exit() instead
(Since version 2.10.0) Use .toDouble for explicit conversion and Float.float2double for implicit conversion
(Since version 2.9.0) Use formatString.format(args: _*) or arg.formatted(formatString) instead
(Since version 2.10.0) Use .toDouble for explicit conversion and Int.int2double for implicit conversion
(Since version 2.10.0) Use .toFloat for explicit conversion and Int.int2float for implicit conversion
(Since version 2.10.0) Use .toLong for explicit conversion and Int.int2long for implicit conversion
(Since version 2.10.0) Use .toDouble for explicit conversion and Long.long2double for implicit conversion
(Since version 2.10.0) Use .toFloat for explicit conversion and Long.long2float for implicit conversion
(Since version 2.10.0) Use .toDouble for explicit conversion and Short.short2double for implicit conversion
(Since version 2.10.0) Use .toFloat for explicit conversion and Short.short2float for implicit conversion
(Since version 2.10.0) Use .toInt for explicit conversion and Short.short2int for implicit conversion
(Since version 2.10.0) Use .toLong for explicit conversion and Short.short2long for implicit conversion
(Since version 2.10.0) Use StringCanBuildFrom
The
Predefobject 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 Map, Set, and the List constructors (scala.collection.immutable.:: and scala.collection.immutable.Nil). The types
Pair(a Tuple2) andTriple(a 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
assertfunctions are provided for use as a way to document and dynamically check invariants in code.assertstatements can be elided at runtime by providing the command line argument-Xdisable-assertionsto thescalacommand.Variants of
assertintended for use with static analysis tools are also provided:assume,requireandensuring.requireandensuringare 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
addNaturalsstates that the list of integers passed should only contain natural numbers (i.e. non-negative), and that the result returned will also be natural.requireis distinct fromassertin that if the condition fails, then the caller of the function is to blame rather than a logical error having been made withinaddNaturalsitself.ensuresis a form ofassertthat 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 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 Array.