I've seen a lot of places where people take a 'temporary' list, and
then remove items from it. The main bug I've seen are
ConcurrentModificationExceptions. You can come across this sort of
thing in web servers, admittedly ones badly written.

This sort of bug is seemingly random and very hard to track down. At
least if you return an immutable list you get the
UnsupportedOperationException more quickly, and in the place you need
to fix. And it indicates to the developer who is using your method
that they need to at least think before they modify it. For me, its
usually a good reaction to return an immutable list.

Matthew.

2011/3/30 [email protected] <[email protected]>:
> A general question to the Immutable fans out there.  In Kevin's
> example he had:
>
>> final List<Widget> widgets = ImmutableList.copyOf(widgetsBuilder)
>
> Is the benefit of having an immutable version of that list, really
> worth wasting the extra memory?  I don't think I can recall ever
> seeing a bug where someone broke a program by accidentally adding
> extra elements to a (temporary) List.
>
> Just curious if people really think this is worthwhile here, or if it
> was just a case of force-of-habit on Kevins part?
>
> Paul

-- 
You received this message because you are subscribed to the Google Groups "The 
Java Posse" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/javaposse?hl=en.

Reply via email to