Java lazy loading of enum instances

前端 未结 2 1348
夕颜
夕颜 2020-12-18 06:02

If I have a bunch of enum instances in an enum type, and if I access an instance of it the first time, all of its remaining instances too are initialized at the same time. I

2条回答
  •  一生所求
    2020-12-18 06:23

    You can make the instances lazy loading on use. i.e. the constructor doesn't actually perform the expensive work. In the methods for these enums, you add a checkingLoaded() method to the methods which need this. This doesn't have to be every method depending on what it does.

提交回复
热议问题