frankiesardo / auto-parcel

Android Parcelable models made easy
Eclipse Public License 1.0
1.37k stars 83 forks source link

Mutable field should make defensive copy in constructor and accessor #34

Closed Piasy closed 9 years ago

Piasy commented 9 years ago

Otherwise, the so called 'immutable' object is actually mutable.

Such as the object contains a List, it can modify the items in the List by both using the reference used to build the object, and using the reference get from the accessor.

frankiesardo commented 9 years ago

That's a very bad idea. If you supply a mutable ArrayList and I make a defensive copy using an ImmutableLinkedList I destroy all your performance assumptions.

No defensive copies under the hood. If you want immutable collections then supply immutable collections. You can do the defensive copy in the factory method.

Piasy commented 9 years ago

Sorry for my lack of deep thought...