Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!mx04.eternal-september.org!.POSTED!not-for-mail From: Jim Janney Newsgroups: comp.lang.java.programmer Subject: Re: diamond operator Date: Fri, 06 Apr 2012 19:56:44 -0600 Organization: ed is the standard editor Lines: 39 Message-ID: <2pbon42tk3.fsf@shell.xmission.com> References: <2pmx6r31q4.fsf@shell.xmission.com> <4f7ec03d$0$6932$e4fe514c@news2.news.xs4all.nl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="PnllQd880uOddfy6hsxHuQ"; logging-data="1391"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Syzd+ruhNgXTtLY6xS0vO" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zvl+Q2l5Zm+KXZwITFgbzdf6xSI= sha1:KvFFE64BE+8V2zdMioXPqfSfeUg= Xref: csiph.com comp.lang.java.programmer:13445 Silvio Bierman writes: > On 04/04/2012 06:23 PM, Jim Janney wrote: >> Roedy Green writes: >> >>> I was looking over the table of contents of a book about new features >>> in Java 7 and came across a reference to the "diamond operator". >>> >>> It turns out to be simple, but one of the precious bits of Java >>> syntactic sugar to make it terser. >>> >>> http://fahdshariff.blogspot.ca/2011/07/java-7-diamond-operator.html >>> >>> http://mindprod.com/book/9781849685627.html >> >> This isn't wrong, but it fixes a problem I never knew I had. Any >> competent IDE will expand that for you anyway. >> > > IDE support is irrelevant in this discussion. Language syntax is not > about typing. > > Code needs to be read and reasoned about. The better the syntax, the > less reading effort needed to be able to reason. Java's redundant > syntax in this respect is inefficient and the diamond operator takes > away part of that. I agree on the importance of readability, but as far as I can tell the diamond operator offers only a fairly minor improvement there: the 1.4 syntax is redundant, yes, but not error prone. When looking at code like Map>> m = new HashMap>>(); I don't need to study the second list of types looking for subtle mistakes: it's either correct or it won't compile. -- Jim Janney