you will find it just references the original list

This is exactly the problem. If I were to gain access to the items of the original collection somehow, then I would be able to modify the internal collection directly. Defensive copying is better since the objects are actually separate and the original copy cannot be modified.

You are right about Collections.unmodifiableList being more space efficient though and if you can guarantee that the internal objects of the collection are not accessible by any external means (hard to do in a complex system) then you could just as well use that instead of deep copying.

I prefer to be on the safe side however and use deep copy or persistent data structures where possible.

Head of UX Engineering at GOJEK

Head of UX Engineering at GOJEK