scala的静态,单列模式

package com.test.scala.test

/**
* 单例对象,这种对象不能提供构造函数
*/
object SingleObject { private var lastnumber=0; def newUnqiueNumber={lastnumber+=1;lastnumber} def main(args: Array[String]): Unit = {
println(newUnqiueNumber)
println(newUnqiueNumber)
println(newUnqiueNumber)
println(newUnqiueNumber)
println(newUnqiueNumber)
println(newUnqiueNumber)
println(SingleObject.lastnumber)
newUnqiueNumber
println(SingleObject.lastnumber)
}
}
上一篇:cf D. Pair of Numbers


下一篇:yii2 or查询