In Java, what is a shallow copy?

A shallow copy just copies the values of the references in the class. A deep copy copies the values. given: class Foo { private Bar myBar; … public Foo shallowCopy() { Foo newFoo = new Foo(); newFoo.myBar = myBar; return newFoo; } public Foo deepCopy() { Foo newFoo = new Foo(); newFoo.myBar = myBar.clone(); //or … Read more