Force initialization of Scala singleton object

后端 未结 4 1624
有刺的猬
有刺的猬 2020-12-15 08:16

I\'m working on an automatic mapping framework built on top of Dozer. I won\'t go into specifics as it\'s not relevant to the question but in general it\'s supposed to allow

4条回答
  •  不思量自难忘°
    2020-12-15 08:56

    Short answer: You can't. Scala objects are lazy, and are not initialized until first reference. You could reference the object, but then you need a way of ensuring the executing code gets executed, reducing the problem back to the original problem.

提交回复
热议问题