Way to achieve static fields and static methods in Scala Object keyword is used to achieve
1. tools, tools and methods to store constants
Example 2. The single-mode
package day03 import scala.collection.mutable.ArrayBuffer object SingletonDemo { def main(args: Array[String]): Unit = { val sessionFactory = SessionFactory println(sessionFactory.getSession) println(sessionFactory.getSession.size) println(sessionFactory.removeSession) } } object SessionFactory { println("SessionFactory") var i = 5 private val session = new ArrayBuffer[Session] while (i > 0) { session += new Session i -= 1 } def getSession = session def removeSession : Unit = { session.remove(0) println("session " + session(0) + " remove") } } class Session {}