Why are static variables considered evil?

前端 未结 30 2715
既然无缘
既然无缘 2020-11-21 05:04

I am a Java programmer who is new to the corporate world. Recently I\'ve developed an application using Groovy and Java. All through the code I wrote used quite a good numbe

30条回答
  •  后悔当初
    2020-11-21 05:45

    Evil is a subjective term.

    You don't control statics in terms of creation and destruction. They live at the behest of the program loading and unloading.

    Since statics live in one space, all threads wishing to use them must go through access control that you have to manage. This means that programs are more coupled and this change is harder to envisage and manage (like J Skeet says). This leads to problems of isolating change impact and thus affects how testing is managed.

    These are the two main issues I have with them.

提交回复
热议问题