Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!post01.iad.highwinds-media.com!newsfe18.iad.POSTED!83aa503d!not-for-mail From: Daniel Pitts User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Converting Sets References: <11fki7dcr12je80bqi6q7ml6f0tc78965a@4ax.com> <4f2a767d$0$449$426a34cc@news.free.fr> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Lines: 21 Message-ID: X-Complaints-To: abuse@newsrazor.net NNTP-Posting-Date: Thu, 02 Feb 2012 19:02:01 UTC Date: Thu, 02 Feb 2012 11:02:01 -0800 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11713 On 2/2/12 5:32 AM, Roedy Green wrote: > On Thu, 02 Feb 2012 12:47:58 +0100, Mayeul > wrote, quoted or indirectly quoted someone who said : > >> Conversion of a Set to a Set, ensuring the Set contains >> objects assignable to Y, but no new elements can be added to it: >> >> Set setOfX = obtainSetOfX(); >> Set setOfY = setOfX; > > This what I was looking for , that did not require an element by > element copy. > Ah, but this this you created is NOT a Set. You cannot add > arbirary Y to it, just more X. I feel queasy. How could the compiler > keep track that setOfY could only contain X. It does not. Instead, it prevents you from any add operation which requires the type. In other words, setOfY becomes somewhat "read-only" for typed operations. You can still clear it, or sub-sets of it, but you can no longer add *any* object to it, whatever type.