我想复制我的对象Kunde
,它与我的Ansprechpartner
对象处于双向关联关系,而不会收到递归。
复制功能Kunde
public void Copy(Kunde another) {
this.m_sKunde_nr = another.getKunde_nr();
this.m_sMdkz = another.getMdkz();
this.m_sName = another.getName();
this.m_sStrasse = another.getStrasse();
this.m_sPlz = another.getPlz();
this.m_sOrt = another.getOrt();
this.m_sTelnr = another.getTelnr();
this.m_sEmail_auftrag = another.getEmail_auftrag();
this.m_sEmail_allgemein = another.getEmail_allgemein();
this.m_dbLng = another.getLng();
this.m_dbLat = another.getLat();
for(Ansprechpartner a : another.getAnsprechpartner()) {
this.m_lAnsprechpartner.add(new Ansprechpartner());
this.m_lAnsprechpartner.get(this.m_lAnsprechpartner.size()-1).Copy(a);
}
}
复制功能Ansprechpartner
public void Copy(Ansprechpartner another) {
this.m_nAnsprechpartner_nr = another.getAnsprechpartner_nr();
this.m_sMdkz = another.getMdkz();
this.m_sName = another.getName();
this.m_sTelnr = another.getTelnr();
this.m_sEmail = another.getEmail();
this.m_sVerantwortlichkeit = another.getVerantwortlichkeit();
this.m_kunde = new Kunde();
this.m_kunde.Copy(another.getKunde());
}
有没有办法在不获取StackOverFlow的情况下执行此操作?
答案 0 :(得分:1)
是的,当然有这样的方式,
复制函数Ansprechpartner
中的只是不复制/创建Kunde
实例,而是通过参数传递它(来自复制函数Kunde
传递this
)。