The collection saves different objects, and finally traverses and displays the data in all objects, and finds the cause of the same data problem

Question: We found that different variables are obviously stored, among which the variables x, y, and degree are all randomly generated, but when stored in the collection, it is displayed as the last data stored in the object.

 reason:

When we define variables, we define static variables (global variables), which will be initialized outside the class, and this variable will share its resources with other objects. When we repeatedly assign values ​​​​to static (static) variables, the variables previously assigned in other objects will be overwritten (resource sharing).

Guess you like

Origin blog.csdn.net/weixin_62222095/article/details/127193091