0603.scala.Predef

Package scala

Scala 在互操作性上例如與 Java 平台時, 在預設的情況, 除了 import 本身的 scala 主套件外, 並 import java.lang 套件; 相對的在 .NET 平台時, import system 套件; 這時 Scala 如何來預定當名稱例如 String 類別在被調用時, 該叫用 scala 或者 java.lang 的呢 ?




反編譯 scala bytecode


任何由 scalac 所產出的 bytecode 在經過反編譯後, 都包含著以下的內容,

import scala.Predef.;
import scala.ScalaObject;

public final class
  implements ScalaObject
{ ...

Predef..MODULE$.println(a);



Predef Object


object Predef
extends AnyRef
The Predef object provides definitions that are accessible in all Scala compilation units without explicit qualification.
...
def
currentThread : java.lang.Thread





保留詞: type



38      @deprecated("use <code>java.lang.Integer</code> instead")
39      type Integer = java.lang.Integer
40      @deprecated("use <code>java.lang.Character</code> instead")
41      type Character = java.lang.Character
42   
43      type String        = java.lang.String
44      type Class[T]      = java.lang.Class[T]
45      type Runnable      = java.lang.Runnable
46   
47      type Throwable = java.lang.Throwable
48      type Exception = java.lang.Exception
49      type Error     = java.lang.Error

...

168      // printing and reading -----------------------------------------------
169   
170      def print(x: Any) = Console.print(x)
171      def println() = Console.println()
172      def println(x: Any) = Console.println(x)
173      def printf(text: String, xs: Any*) = Console.printf(text, xs: _*)
174      def format(text: String, xs: Any*) = stringWrapper(text).format(xs: _*)
175   
176      def readLine(): String = Console.readLine()
177      def readLine(text: String, args: Any*) = Console.readLine(text, args)
178      def readBoolean() = Console.readBoolean()
179      def readByte() = Console.readByte()
180      def readShort() = Console.readShort()
181      def readChar() = Console.readChar()
182      def readInt() = Console.readInt()
183      def readLong() = Console.readLong()
184      def readFloat() = Console.readFloat()
185      def readDouble() = Console.readDouble()
186      def readf(format: String) = Console.readf(format)
187      def readf1(format: String) = Console.readf1(format)
188      def readf2(format: String) = Console.readf2(format)
189      def readf3(format: String) = Console.readf3(format)


Comments