Singleton

scala.Singleton
final open trait Singleton

Singleton is used by the compiler as a supertype for singleton types. This includes literal types, as they are also singleton types.

scala> object A { val x = 42 }
defined object A

scala> implicitly[A.type  implicitly[A.x.type  implicitly[42  implicitly[Int  def check42[T](x: T)(implicit ev: T =:= 42): T = x
check42: [T](x: T)(implicit ev: T =:= 42)T

scala> val x1 = check42(42)
^
error: Cannot prove that Int =:= 42.

scala> def singleCheck42[T  val x2 = singleCheck42(42)
x2: Int = 42

See also SIP-23 about Literal-based Singleton Types.

Attributes

Graph
Supertypes
class Any

Members list

Type members

Types

type Self