Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.java.programmer Subject: Re: Blocks for scope control Date: Mon, 16 Jan 2012 07:59:19 +0100 Lines: 32 Message-ID: <9ni06jF9acU1@mid.individual.net> References: <9ngdd9Fv6mU1@mid.individual.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net xToIQORLMq8XXUr7x+SYTAmUFYdsvIxU+Z0qFlp9K9Rs2w7Lo= Cancel-Lock: sha1:QuIPTLyyBXcTfAYt0Wc2qMOqDC8= User-Agent: Mozilla/5.0 (Windows NT 6.0; WOW64; rv:9.0) Gecko/20111222 Thunderbird/9.0.1 In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:11373 On 15.01.2012 17:59, Stefan Ram wrote: > Robert Klemme writes: >>> { final Button button = new Button(); frame.add( button ); } >> Why do you think it makes sense to replace this >> frame.add( new Button() ); >> with the block above? > > This code (comments removed by me): > > for (ThumbnailAction thumbAction : chunks) { > JButton thumbButton = new JButton(thumbAction); > buttonBar.add(thumbButton, buttonBar.getComponentCount() - 1); > } > > can be found in the renowned Java Tutorial at > > http://docs.oracle.com/javase/tutorial/uiswing/components/icon.html > > . So such temporary names for one-time use are not > against common teachings. OK, but here there are more arguments to add() and the line is longer. That makes more sense than the original example to me. Cheers robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/