predef.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 356 行 · 第 1/2 页

SCALA
356
字号
/*                     __                                               *\**     ________ ___   / /  ___     Scala API                            ****    / __/ __// _ | / /  / _ |    (c) 2002-2008, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: Predef.scala 14543 2008-04-07 15:57:07Z odersky $package scala/** The <code>Predef</code> object provides definitions that are *  accessible in all Scala compilation units without explicit *  qualification. */object Predef {  // classOf dummy ------------------------------------------------------  /** Return the runtime representation of a class type. */  def classOf[T]: Class[T] = null  // aliases ------------------------------------------------------------  type byte    = scala.Byte  type short   = scala.Short  type char    = scala.Char  type int     = scala.Int  type long    = scala.Long  type float   = scala.Float  type double  = scala.Double  type boolean = scala.Boolean  type unit    = scala.Unit  /** @deprecated use <code>java.lang.Integer</code> instead */  @deprecated type Integer = java.lang.Integer  /** @deprecated use <code>java.lang.Character</code> instead */  @deprecated type Character = java.lang.Character  type String        = java.lang.String  type Class[T]      = java.lang.Class[T]  type Runnable      = java.lang.Runnable  type Throwable = java.lang.Throwable  type Exception = java.lang.Exception  type Error     = java.lang.Error  type RuntimeException                = java.lang.RuntimeException  type NullPointerException            = java.lang.NullPointerException  type ClassCastException              = java.lang.ClassCastException  type IndexOutOfBoundsException       = java.lang.IndexOutOfBoundsException  type ArrayIndexOutOfBoundsException  = java.lang.ArrayIndexOutOfBoundsException  type StringIndexOutOfBoundsException = java.lang.StringIndexOutOfBoundsException  type UnsupportedOperationException   = java.lang.UnsupportedOperationException  type IllegalArgumentException        = java.lang.IllegalArgumentException  type NoSuchElementException          = java.util.NoSuchElementException  type NumberFormatException           = java.lang.NumberFormatException  // miscelleaneous -----------------------------------------------------    val $scope = scala.xml.TopScope  type Function[-A, +B] = Function1[A, B]  type Map[A, B] = collection.immutable.Map[A, B]  type Set[A] = collection.immutable.Set[A]  val Map = collection.immutable.Map  val Set = collection.immutable.Set  // errors and asserts -------------------------------------------------  def error(message: String): Nothing = throw new RuntimeException(message)  def exit: Nothing = exit(0)  def exit(status: Int): Nothing = {    java.lang.System.exit(status)    throw new Throwable()  }  def assert(assertion: Boolean) {    if (!assertion)      throw new java.lang.AssertionError("assertion failed")  }  def assert(assertion: Boolean, message: Any) {    if (!assertion)      throw new java.lang.AssertionError("assertion failed: "+ message)  }  def assume(assumption: Boolean) {    if (!assumption)      throw new java.lang.AssertionError("assumption failed")  }  def assume(assumption: Boolean, message: Any) {    if (!assumption)      throw new java.lang.AssertionError("assumptopm failed: "+ message)  }  def require(requirement: Boolean) {    if (!requirement)      throw new IllegalArgumentException("requirement failed")  }  def require(requirement: Boolean, message: Any) {    if (!requirement)      throw new IllegalArgumentException("requirement failed: "+ message)  }  // tupling ------------------------------------------------------------  type Pair[+A, +B] = Tuple2[A, B]  object Pair {    def apply[A, B](x: A, y: B) = Tuple2(x, y)    def unapply[A, B](x: Tuple2[A, B]): Option[Tuple2[A, B]] = Some(x)  }  type Triple[+A, +B, +C] = Tuple3[A, B, C]  object Triple {    def apply[A, B, C](x: A, y: B, z: C) = Tuple3(x, y, z)    def unapply[A, B, C](x: Tuple3[A, B, C]): Option[Tuple3[A, B, C]] = Some(x)  }  class Ensuring[A](x: A) {    def ensuring(cond: Boolean): A = { assert(cond); x }    def ensuring(cond: Boolean, msg: Any): A = { assert(cond, msg); x }    def ensuring(cond: A => Boolean): A = { assert(cond(x)); x }    def ensuring(cond: A => Boolean, msg: Any): A = { assert(cond(x), msg); x }  }  implicit def any2Ensuring[A](x: A): Ensuring[A] = new Ensuring(x)  class ArrowAssoc[A](x: A) {    def -> [B](y: B): Tuple2[A, B] = Tuple2(x, y)  }  implicit def any2ArrowAssoc[A](x: A): ArrowAssoc[A] = new ArrowAssoc(x)  def Tuple[A1](x1: A1) = Tuple1(x1)  def Tuple[A1, A2](x1: A1, x2: A2) = Tuple2(x1, x2)  def Tuple[A1, A2, A3](x1: A1, x2: A2, x3: A3) = Tuple3(x1, x2, x3)  def Tuple[A1, A2, A3, A4](x1: A1, x2: A2, x3: A3, x4: A4) = Tuple4(x1, x2, x3, x4)  def Tuple[A1, A2, A3, A4, A5](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5) = Tuple5(x1, x2, x3, x4, x5)  def Tuple[A1, A2, A3, A4, A5, A6](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6) = Tuple6(x1, x2, x3, x4, x5, x6)  def Tuple[A1, A2, A3, A4, A5, A6, A7](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7) = Tuple7(x1, x2, x3, x4, x5, x6, x7)  def Tuple[A1, A2, A3, A4, A5, A6, A7, A8](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8) = Tuple8(x1, x2, x3, x4, x5, x6, x7, x8)  def Tuple[A1, A2, A3, A4, A5, A6, A7, A8, A9](x1: A1, x2: A2, x3: A3, x4: A4, x5: A5, x6: A6, x7: A7, x8: A8, x9: A9) = Tuple9(x1, x2, x3, x4, x5, x6, x7, x8, x9)  // printing and reading -----------------------------------------------  def print(x: Any) = Console.print(x)  def println() = Console.println()  def println(x: Any) = Console.println(x)  def printf(text: String, xs: Any*) = Console.printf(text, xs: _*)  def format(text: String, xs: Any*) = Console.format(text, xs: _*)  def readLine(): String = Console.readLine()  def readLine(text: String, args: Any*) = Console.readLine(text, args)  def readBoolean() = Console.readBoolean()  def readByte() = Console.readByte()  def readShort() = Console.readShort()  def readChar() = Console.readChar()  def readInt() = Console.readInt()  def readLong() = Console.readLong()  def readFloat() = Console.readFloat()  def readDouble() = Console.readDouble()  def readf(format: String) = Console.readf(format)  def readf1(format: String) = Console.readf1(format)  def readf2(format: String) = Console.readf2(format)  def readf3(format: String) = Console.readf3(format)    // views --------------------------------------------------------------  implicit def identity[A](x: A): A = x

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?