By studying some projects, I found an intriguing code, where in addition to the class
clause that defines an object, already known in Java, there is the object
clause, unknown to me until then.
object Counter {
val InitialValue = 10000000L; // (ten million)
val CounterKey = "counter"
}
@Singleton
class Counter @Inject()(
client: JedisClient) {
def next: Long = {
val current: Long = Option(client.get(CounterKey)) match {
case Some(value) =>
value.toLong
case None =>
InitialValue
}
val nextValue = current + 1
client.set(CounterKey, nextValue.toString)
nextValue
}
}
What does object Counter
define in this case?