Predef (original) (raw)
Utility Methods
???
can be used for marking methods that remain to be implemented.
???
can be used for marking methods that remain to be implemented.
Attributes
Throws
Source
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.
Attributes
Returns
The runtime Class representation of type T
.
Example
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
Source
A method that returns its input value.
A method that returns its input value.
Type parameters
A
type of the input value x.
Value parameters
x
the value of type A
to be returned.
Attributes
Returns
the value x
.
Source
Summon an implicit value of type T
.
Summon an implicit value of type T
. Usually, the argument is not passed explicitly.
Type parameters
T
the type of the value to be summoned
Attributes
Returns
the implicit value of type T
Source
Used to mark code blocks as being expressions, instead of being taken as part of anonymous classes and the like.
Used to mark code blocks as being expressions, instead of being taken as part of anonymous classes and the like. This is just a different name for identity.
Attributes
Example
Separating code blocks from new
:
val x = new AnyRef
{
val y = ...
println(y)
}
// the { ... } block is seen as the body of an anonymous class
val x = new AnyRef
{
val y = ...
println(y)
}
// an empty line is a brittle "fix"
val x = new AnyRef
locally {
val y = ...
println(y)
}
// locally guards the block and helps communicate intent
Source
Retrieve the single value of a type with a unique inhabitant.
Retrieve the single value of a type with a unique inhabitant.
Attributes
Example
object Foo
val foo = valueOf[Foo.type]
// foo is Foo.type = Foo
val bar = valueOf[23]
// bar is 23.type = 23
Source
Assertions
These methods support program verification and runtime correctness.
Tests an expression, throwing an AssertionError
if false.
Tests an expression, throwing an AssertionError
if false. Calls to this method will not be generated if -Xelide-below
is greater than ASSERTION
.
Value parameters
assertion
the expression to test
Attributes
See also
Source
Tests an expression, throwing an AssertionError
if false.
Tests an expression, throwing an AssertionError
if false. Calls to this method will not be generated if -Xelide-below
is greater than ASSERTION
.
Value parameters
assertion
the expression to test
message
a String to include in the failure message
Attributes
See also
Source
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 greater than ASSERTION
.
Value parameters
assumption
the expression to test
Attributes
See also
Source
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 greater than ASSERTION
.
Value parameters
assumption
the expression to test
message
a String to include in the failure message
Attributes
See also
Source
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.
Value parameters
requirement
the expression to test
Attributes
Source
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.
Value parameters
message
a String to include in the failure message
requirement
the expression to test
Attributes
Source
Console Output
These methods provide output via the console.
Prints an object to out
using its toString
method.
Prints an object to out
using its toString
method.
Value parameters
x
the object to print; may be null.
Attributes
Source
Prints its arguments as a formatted string to the default output, based on a string pattern (in a fashion similar to printf in C).
Prints its arguments as a formatted string to the default output, based on a string pattern (in a fashion similar to printf in C).
The interpretation of the formatting patterns is described in java.util.Formatter.
Consider using the f interpolator as more type safe and idiomatic.
Value parameters
text
the pattern for formatting the arguments.
xs
the arguments used to instantiate the pattern.
Attributes
Throws
See also
Source
Prints a newline character on the default output.
Prints a newline character on the default output.
Attributes
Source
Prints out an object to the default output, followed by a newline character.
Prints out an object to the default output, followed by a newline character.
Value parameters
x
the object to print.
Attributes
Source
Aliases
These aliases bring selected immutable types into scope without any imports.
Allows destructuring tuples with the same syntax as constructing them.
Allows destructuring tuples with the same syntax as constructing them.
Attributes
Example
val tup = "foobar" -> 3
val c = tup match {
case str -> i => str.charAt(i)
}
Source
The String
type in Scala has all the methods of the underlying java.lang.String, of which it is just an alias.
String Conversions
Conversions from String to StringOps or WrappedString.
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Implicit Classes
These implicit classes add useful extension methods to every type.
Injects String concatenation operator +
to any classes.
Injects String concatenation operator +
to any classes.
Attributes
Deprecated
[Since version 2.13.0]
Implicit injection of + is deprecated. Convert to String to call +
Source
Supertypes
Injects String concatenation operator +
to any classes.
Injects String concatenation operator +
to any classes.
Attributes
Deprecated
[Since version 2.13.0]
Implicit injection of + is deprecated. Convert to String to call +
Source
CharSequence Wrappers
Wrappers that implements CharSequence and were implicit classes.
Java to Scala
Implicit conversion from Java primitive wrapper types to Scala equivalents.
Scala to Java
Implicit conversion from Scala AnyVals to Java primitive wrapper types equivalents.
Array to ArraySeq
Conversions from Arrays to ArraySeqs.
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
A type supporting Self-based type classes.
A type supporting Self-based type classes.
A is TC
expands to
TC { type Self = A }
which is what is needed for a context bound [A: TC]
.
Attributes
Source
Summon a given value of type T
. Usually, the argument is not passed explicitly.
Summon a given value of type T
. Usually, the argument is not passed explicitly.
Type parameters
T
the type of the value to be summoned
Attributes
Returns
the given value typed: the provided type parameter
Source
Strips away the nullability from a value. Note that .nn
performs a checked cast, so if invoked on a null
value it will throw an NullPointerException
.
Strips away the nullability from a value. Note that .nn
performs a checked cast, so if invoked on a null
value it will throw an NullPointerException
.
Attributes
Example
val s1: String | Null = "hello"
val s2: String = s1.nn
val s3: String | Null = null
val s4: String = s3.nn // throw NullPointerException
Source
Enables an expression of type T|Null
, where T
is a subtype of AnyRef
, to be checked for null
using eq
rather than only ==
. This is needed because Null
no longer has eq
or ne
methods, only ==
and !=
inherited from Any
.
Enables an expression of type T|Null
, where T
is a subtype of AnyRef
, to be checked for null
using eq
rather than only ==
. This is needed because Null
no longer has eq
or ne
methods, only ==
and !=
inherited from Any
.
Attributes
Source
Enables an expression of type T|Null
, where T
is a subtype of AnyRef
, to be checked for null
using ne
rather than only !=
. This is needed because Null
no longer has eq
or ne
methods, only ==
and !=
inherited from Any
.
Enables an expression of type T|Null
, where T
is a subtype of AnyRef
, to be checked for null
using ne
rather than only !=
. This is needed because Null
no longer has eq
or ne
methods, only ==
and !=
inherited from Any
.
Attributes
Source
Asserts that a term should be exempt from static checks that can be reliably checked at runtime.
Asserts that a term should be exempt from static checks that can be reliably checked at runtime.
Attributes
Example
val xs: Option[Int] = Option(1)
xs.runtimeChecked match
case Some(x) => x // `Some(_)` can be checked at runtime, so no warning
val xs: List[Int] = List(1,2,3)
val y :: ys = xs.runtimeChecked // `_ :: _` can be checked at runtime, so no warning
Experimental
true
Source
An implicit of type A => A
is available for all A
because it can always be implemented using the identity function.
An implicit of type A => A
is available for all A
because it can always be implemented using the identity function. This also means that an implicit of type A => B
is always available when A <: B
, because (A => A) <: (A => B)
.
Attributes
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
We prefer the java.lang.* boxed types to these wrappers in any potential conflicts.
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!
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Inherited from:
LowPriorityImplicits (hidden)
Source
Attributes
Deprecated
[Since version 2.13.0]
implicit conversions from Array to immutable.IndexedSeq are implemented by copying; use `toIndexedSeq` explicitly if you want to copy, or use the more efficient non-copying ArraySeq.unsafeWrapArray
Inherited from:
LowPriorityImplicits2 (hidden)
Source