Why are static variables considered evil?

前端 未结 30 2791
既然无缘
既然无缘 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 06:08

    It might be suggested that in most cases where you use a static variable, you really want to be using the singleton pattern.

    The problem with global states is that sometimes what makes sense as global in a simpler context, needs to be a bit more flexible in a practical context, and this is where the singleton pattern becomes useful.

提交回复
热议问题