Why are static variables considered evil?

前端 未结 30 2713
既然无缘
既然无缘 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:52

    There are 2 main problems with static variables:

    • Thread Safety - static resources are by definition not thread-safe
    • Code Implicity - You do not know when a static variables is instantiated and whether or not it will be instantiated before another static variable

提交回复
热议问题