Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么会发生这种情况,如何避免?如何避免?
您不是在克隆对象,而只是在执行 objX =objY 时复制引用。使用正确实施的克隆方法。
克隆:
public Class X{ public String A; public String B; public X Clone(){ X cl = new X(); cl.A = this.A; cl.B = this.B; return cl; } }
语法可能不是 100% 正确的。