How to fix “Constructor Calls Overridable Method”

后端 未结 4 1831
无人及你
无人及你 2021-01-01 23:59

I have the following setup which is giving me a message stating that \"Constructor Calls Overridable Method\". I know this is happening, but my question is how to fix it so

4条回答
  •  臣服心动
    2021-01-02 00:29

    Your IDE is telling you that, because it is potentially unsafe. You can provide any implimentation or doFoo and make all Bar objects to different stuff on startup. This seems like a bad choice of design in most cases.

    It seems like you are using a strategy pattern, in a constructor. It's not wise to use a strategy or any other overidable behaviour in the constructor. Use it some place else.

提交回复
热议问题