On 30 March 2011 04:18, Alexey Zinger <[email protected]> wrote:

> There's very little memory or performance overhead.  There's no deep copy.
> The returned collection is a proxy to the underlying one, insuring
> immutability.
>

I'm using immutable collections from Google Guava here, which *do* take a
copy.  The advantage is that they're then immune to subsequent changes in
the collection that was originally copied.  You're getting confused with
Unmodifiable collections from the standard Java API.

The speed benefits come later, where you no longer have to make defensive
copies when returning such a collection in your own APIs.

As Paul suggested, this isn't exactly relevant to the discussion at hand,
it's just a best practice that I now adopt as force of habit when working
with Java.  I find that it's far easier to reason about code if I can skip
logic between the time a collection was created and the time it's actually
used, knowing that intervening changes simply aren't possible.


>
> Alexey
>
>
> ------------------------------
> *From:* "[email protected]" <[email protected]>
> *To:* The Java Posse <[email protected]>
> *Sent:* Tue, March 29, 2011 10:50:58 PM
> *Subject:* [The Java Posse] Re: How to deal with CheckedExceptions
>
> 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 javaposse+
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/javaposse?hl=en.
>
>  --
> 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.
>



-- 
Kevin Wright

gtalk / msn : [email protected]
<[email protected]>mail: [email protected]
vibe / skype: kev.lee.wright
quora: http://www.quora.com/Kevin-Wright
twitter: @thecoda

"My point today is that, if we wish to count lines of code, we should not
regard them as "lines produced" but as "lines spent": the current
conventional wisdom is so foolish as to book that count on the wrong side of
the ledger" ~ Dijkstra

-- 
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