Path: csiph.com!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Steven Simpson Newsgroups: comp.lang.java.programmer Subject: Re: hashtables syntax Date: Mon, 16 May 2016 15:51:59 +0100 Organization: A noiseless patient Spider Lines: 46 Message-ID: References: <338d0b8c-9a5e-ccc0-9a5c-792c870f84bf@mrbrklyn.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: mx02.eternal-september.org; posting-host="0f928dddd1117028fbe6efb26c856d65"; logging-data="18257"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Bfjmyr7oTwSqBtuCCEW73lURlA+IS1Pc=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 In-Reply-To: Cancel-Lock: sha1:qPF2Yl/prdtc6wLIaS3aCuCbv+g= Xref: csiph.com comp.lang.java.programmer:34304 On 16/05/16 12:48, Eric Sosman wrote: > On 5/16/2016 1:26 AM, ruben safir wrote: >> Gotchya, but it seems inconsistent. >> >> >> why not like >> >> HashMap<> function = new HashMap > > With what is this "inconsistent?" I'm not seeing your point. > > The types must be specified on one side or the other; Java > decided to insist that they appear on the left. Java *could* > have chosen to have them on the right (I suppose, but there may > be considerations I'm unaware of), but it chose the left. Shrug. It would arguably be inappropriate to put the type information 'on the right' in the the OP's case, where the declaration of the reference is separate from its assignment. The generic parameters would be visible only within the static initializer, while the declaration is visible throughout. Imagine: private static HashMap<> functions; static { // initialize function types functions = new HashMap(); Compile-time checking of calls like functions.get(20) would have to inspect the static initializer, rather than the declaration. Also, I expect it would be more complex to inspect situations like this: private static HashMap<> functions; // at some point functions = new HashMap(); // later functions = new HashMap(); The declaration acts as a kind of rendezvous point between users and providers of 'function', so it makes sense to propagate type information out from that point. -- ss at comp dot lancs dot ac dot uk