Java sharing same values in a class

后端 未结 4 504
不知归路
不知归路 2021-01-29 13:03

I have a class called Hand and another class to test it. Hand uses global variables and change their values with some methods if in class test I create

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-29 13:38

    Make private List hand = new ArrayList(); as instance variable rather then make it static..
    Coz static is property of class and instance variables are property of Object... which is different for different Object ..but in case of static they are same for all objects..

提交回复
热议问题