Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!weretis.net!feeder1.news.weretis.net!feeder.erje.net!xlned.com!feeder3.xlned.com!feeder.news-service.com!94.75.214.39.MISMATCH!aioe.org!.POSTED!not-for-mail From: supercalifragilisticexpialadiamaticonormalizeringelimatisticantations Newsgroups: comp.lang.java.programmer Subject: Re: Why "lock" functionality is introduced for all the objects? Date: Sat, 02 Jul 2011 00:26:14 -0400 Organization: supercalifragilisticexpialadiamaticonormalizeringelimatisticantations Lines: 31 Message-ID: References: NNTP-Posting-Host: 4/raLmFi1848LMFwwllsmA.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: WinVN 0.99.12z (x86 32bit) X-Notice: Filtered by postfilter v. 0.8.2 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:5819 On 01/07/2011 10:05 PM, Joshua Cranmer wrote: > On 6/28/2011 10:12 PM, > supercalifragilisticexpialadiamaticonormalizeringelimatisticantations > wrote: >> If the list wasn't mutable there'd be no problem casting a >> List to a List. > > And then I'd complain because my program would be spending more time > copying the values between immutable queues than actually doing work. As > long as the language has the potential for mutable collections (which > most people want for performance reasons), you have the potential for > generics casting issues. Lists are, in my experience, typically constructed, then consumed; only infrequently is a mutable one maintained with recurring episodes of reading and writing over time. The common case could have been optimized with better support than the various Collections.unmodifiableFoo() methods provide. For example, if you could tag a list as not modifiable the compiler can both disallow writing through it and allow casting from UnmodifiableList to UnmodifiableList. We kinda have that now in that we can cast List to List and then the compiler will indeed not let us add to it, but is both awkward and not equal to Super. A lot of methods might be written to demand a List even if they won't modify the list, and will thus work with a List. More generally it complicates generics. The fact of the matter is that is like of like "unmodifiable, and also ", at least for collections; a more clear way of (separately) expressing "unmodifiable" would have been nice. So, basically, what I'm saying is that we should have had some notion of constness in Java. :)