0

我想复制我的对象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 的情况下做到这一点?

4

1 回答 1

1

是的当然有这样的方法,

在复制函数中Ansprechpartner根本不复制/创建Kunde实例,而是通过参数传递它(来自复制函数Kundepass this)。

于 2013-10-16T14:20:07.467 回答