how to access a non static member from a static method in java?

前端 未结 5 1718
刺人心
刺人心 2020-12-22 12:35

I have a situation where i have to access a non static member from inside a static method. I can access it with new instance, but current state will be lost as non static me

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-22 12:54

    You can't. A static method is not associated with any particular state (aka any non-static members). In other words, they operate independently of any particular instance of the class so they cannot depend on non-static members.

提交回复
热议问题