Objects are single instances of their own definitions.
object IdFactory { private var counter = 0 def create(): Int = { counter += 1 counter } } val newId: Int = IdFactory.create() println(newId) // 1 val newerId: Int = IdFactory.create() println(newerId) // 2
Last updated 6 years ago