Scope of Java static member in web applications

前端 未结 2 1151
故里飘歌
故里飘歌 2021-01-12 10:54

Are Java static variables shared across instances of the same web application?

class MyClass
{
    private static SomeClass myStaticObject = new SomeClass();         


        
2条回答
  •  伪装坚强ぢ
    2021-01-12 11:20

    I don't quite see the point of having a private static variable in MyClass. If it's private you cannot access it as a class variable from outside the class you defined it in. If you just want other classes to access this variable via a getter method you should remove the static keyword.

提交回复
热议问题