mardi 5 mai 2015

Create a deepy-copy of object to implement the Pattern Memento in Java

I,ve defined a Java class named Memento. It has 2 attributes implemented as an ArrayList. I've defined a constructor that works. But I need a second constructor, a copy-constructor to make a deep-copy. But I have an error : "Recurvise constructor invocation". Can anyone help me please to fix it? Thanks a lot.

Below the code :

public class Memento {

    private List<Mushroom> mementoMushrooms;
    private List<Mario> mementoMarios;
    private int mementoIdSelectedMario;

    // This works
    public Memento(List<Mushroom> mementoMushrooms, List<Mario> mementoMarios, int mementoIdSelectedMario){
        this.mementoMushrooms = mementoMushrooms;
        this.mementoMarios = mementoMarios;
        this.mementoIdSelectedMario = mementoIdSelectedMario;
    }

// Error with this   
public Memento(Memento m){
        this(new ArrayList<>(m.mementoMushrooms), new ArrayList<>(m.mementoMarios), m.mementoIdSelectedMario);
    }

}

Aucun commentaire:

Enregistrer un commentaire