Robert

51%
Flag icon
think about whether the client-provided object is potentially mutable. If it is, think about whether your class could tolerate a change in the object after it was entered into the data structure. If the answer is no, you must defensively copy the object and enter the copy into the data structure in place of the original.
Robert
"Must" is a bit too strong here. Consider whether you need to be part of protecting the caller or the data under your purview. Often times, "caveat emptor" -- with documentation saying so -- should be enough. In other words, consider whether the performance and code complexity tradeoff is worth it. Let's not blindly advise to always hand-hold the consumer.
Brian
· Flag
Brian
i don't know. this sounds like smart defensive programming to me. trying to think of where the burden is too high that this would not make sense. i'd hope the copying is a one liner. i guess the best …
Effective Java: A Programming Language Guide (Java Series)
Rate this book
Clear rating
Open Preview