Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Robbie Brown Newsgroups: comp.lang.java.programmer Subject: Re: What is your favorite WC++IETJ? Date: Thu, 30 Apr 2015 20:37:40 +0100 Organization: A noiseless patient Spider Lines: 45 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 30 Apr 2015 19:36:40 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="1472fcbe5105b2f1a291b5cf6efc19de"; logging-data="11370"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kHMaRy5gEw1az3fBOtsh/8BL7IklOIMA=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 In-Reply-To: Cancel-Lock: sha1:OLc84yXIbx8iZJVUZJNrwiDdZpI= Xref: csiph.com comp.lang.java.programmer:31635 On 30/04/15 14:58, Stefan Ram wrote: > ram@zedat.fu-berlin.de (Stefan Ram) writes: >> . Now, we want to generalize and omit some specializations >> (details): >> Set result = new HashSet<>(); > > The general idea of an assignment in Java is: > > supertypeVariable = subtypeExpression > > , however in the case of > > Set result = new HashSet<>() > > now, confusingly, the more general designation »<>« > appears on the right side, while the more special > designation »« appears on the left side. The generalization is on the left, the rhs is simply shorthand to stop us having to write Set result = new HashSet() which used to cause howls of protest from even experienced Java developers. Try compiling Set result = new HashSet() if the rhs was a generalization we should be able to generalize but we can't. HashSet<>() is not a generalization it is simply shorthand. The Generalization Set allows for information hiding, a fundamental concept behind the idea of encapsulation. public Set getFoo(){ Set x = new HashSet(); ... return x; } the implementation of x can be changed without affecting clients of getFoo(); Seems perfectly reasonable to me. -- Not floundering ... just fishing