The Prototype pattern's biggest pitfall is getting clone semantics wrong, specifically the choice between shallow and deep copying. A prototype is only useful if cloning produces an object that behaves independently from the original, so mishandling this defeats the pattern's purpose.
Cloning a Person object that has a List<Address> field with a shallow copy leaves both the original and the clone pointing at the same list, so adding an address to the clone also changes the original's address list.
import java.util.ArrayList;
import java.util.List;
public class PrototypePitfall {
static class Person implements Cloneable {
String name;
List<String> addresses = new ArrayList<>();
// Pitfall: Object.clone() copies the reference to the same list
Person shallowClone() throws CloneNotSupportedException {
return (Person) super.clone();
}
// Fix: copy mutable fields as well
Person deepClone() throws CloneNotSupportedException {
Person p = (Person) super.clone();
p.addresses = new ArrayList<>(addresses);
return p;
}
}
public static void main(String[] args) throws Exception {
Person original = new Person();
original.name = "Ravi";
original.addresses.add("Pune");
Person shallow = original.shallowClone();
shallow.addresses.add("Mumbai");
System.out.println("Shallow: clone added Mumbai, original now has " + original.addresses);
Person fresh = new Person();
fresh.addresses.add("Pune");
Person deep = fresh.deepClone();
deep.addresses.add("Delhi");
System.out.println("Deep: clone added Delhi, original still has " + fresh.addresses);
}
}Shallow: clone added Mumbai, original now has [Pune, Mumbai]
Deep: clone added Delhi, original still has [Pune]
A concise interview answer is
The classic pitfall is shallow vs. deep cloning: Java's default clone() is shallow, so any mutable reference fields end up shared between the original and the copy, causing subtle bugs. You have to deliberately deep-copy those fields and keep the clone logic in sync every time the class gains new mutable state.
Last updated: 1 November 2026
Previous question: When would you use the Prototype pattern over creating a new instance?
Next question: What is the Adapter pattern and when would you use it?