Why are static variables considered evil?

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

    There are plenty of good answers here, adding to it,

    Memory: Static variables are live as long as the class loader lives[in general till VM dies], but this is only in-case of bulk objects/references stored as static.

    Modularization: consider concepts like IOC, dependencyInjection, proxy etc.. All are completely against tightly coupling/static implementations.

    Other Con's: Thread Safety, Testability

提交回复
热议问题