Force initialization of Scala singleton object

后端 未结 4 1631
有刺的猬
有刺的猬 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:57

    As Dave Griffith and Don Roby already noted, it cannot be done at JVM startup in general. However maybe this initialization could wait until first use of your framework? If so, and if you don't mind resorting to fragile reflection tricks, in your --> method you could obtain reference to the companion object and get it initialize itself.

    You can start at Getting object instance by string name in scala.

提交回复
热议问题