Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!.POSTED!not-for-mail From: Lew Newsgroups: comp.lang.java.help Subject: Re: Why would one use += 1 at the place of ++? Date: Thu, 19 May 2011 08:08:39 -0400 Organization: albasani.net Lines: 31 Message-ID: References: <8762p7upgn.fsf@merciadriluca-station.MERCIADRILUCA> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.albasani.net X22mVXFgLn/azm871GxLYC1ouBfUBNFtky4FeTEwogtaxTOHWlKGKF+/Pol3IbAoN8NcUpIpr9K0aWX/s5Y888zyZRFAg9brGa/5LXpM+afGLtKWfbOy272FAmmREsbi NNTP-Posting-Date: Thu, 19 May 2011 12:08:12 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="uoQDOH2cfNJCE7dWQ37cbAURMN0TZQU43o+fAMhZ/tXVfBssKl9u1LyJ2oyLEK7HuehCPqpzDum0TGV46ob/zTGw9tLMU2oEmejxrjkEo9cgGq0zNJD7d/hSddTXCCH+"; mail-complaints-to="abuse@albasani.net" User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110424 Thunderbird/3.1.10 In-Reply-To: Cancel-Lock: sha1:uBIzsK8p2VGo9ViNkarkjZDStos= Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.help:696 On 05/19/2011 08:03 AM, Jeff Higgins wrote: > On 05/19/2011 03:19 AM, Merciadri Luca wrote: >> Hi, >> >> I've heard that it is generally better to use += 1 at the place of ++. > > Specifically better here: > String s = "0 + 1 = "; > s += 1; > Maybe someone can come up with a specific case > where the increment operator is better. You can't use the increment operator at all on Strings. So there's no "better" comparison between them, except for the trivial "one compiles, the other doesn't." "The result of the postfix expression must be a variable of a type that is convertible (§5.1.8) to a numeric type, or a compile-time error occurs." - JLS, §15.14.2 > For me, >> they do exactly the same thing, maybe except that the former is >> actually splitted into different atomic operations, when the latter >> might be done in an atomic operation? Nope. -- Lew Honi soit qui mal y pense. http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg