Questions tagged [companion-object]

In Scala and Kotlin, an object with the same name as a class, used to hold utility members for the class

In and , a companion object is an object with the same fully qualified name as a class. Companion objects are used to hold utility members that apply to all instances of the class. These can include constants, s (apply), and s. They provide a similar functionality as Java's .

241 questions
-2
votes
1 answer

Inject mock object to companion object field

I have a Scala class like this: object MyClient { private lazy val theClient: TheClient = new TheClient() } class MyClient { import MyClient._ var client = null // this is only for unittest def getSomethingFromTheClient() = { if…
lznt
  • 2,330
  • 2
  • 22
  • 27
1 2 3
16
17