在斯卡拉,它說的對象是單身。所以我想知道什麼是對象的創建時間。scala對象的創建時間
這就是我創建爲空兩個階文件:
object Singleton {
def Singleton() = {
val time = System.currentTimeMillis()
println("creation time: " + time)
}
def getTime() = {
val time = System.currentTimeMillis()
println("current time: " + time)
}
}
object Test {
def main(args: Array[String]) = {
Singleton.getTime()
Thread sleep 10000
Singleton.getTime()
}
}
輸出是:
current time: 1415180237062
current time: 1415180247299
So when is the Singleton object created??
Scala不是Java。構造函數沒有使用類或對象的名稱作爲方法名稱來定義。 – rightfold 2014-11-05 10:18:05
你是對的,我剛剛改變,並驗證它是在第一次通話期間創建的。 – cheneychen 2014-11-05 10:28:55