Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 11 May 2011 07:24:55 -0500 Date: Wed, 11 May 2011 05:24:48 -0700 From: Patricia Shanahan User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler References: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> In-Reply-To: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Message-ID: Lines: 22 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 75.8.126.96 X-Trace: sv3-IhSLOE8g7BCXeMG22s3UmRD7pgXhUnDJd4VIkN6AdzJS/d7kWsH/uRBsG9xsIzErvOqKoWnbsVpmv+U!EmDdpXz4/yy9F5fR0JKOQOr1sIQzEUKi0dHyTdyTLFFXDBnUNfJ3tgSFb3SFylUe3PVm9/m8+8uI!ZPVUq85QR3KyXhJxsphgapBB/nUy8MIFI/Zu84FMp6I= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2182 Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:3964 On 5/11/2011 1:44 AM, Gábor Bakos wrote: > It worked as specified. I just found unexpected that there is an implicit cast to the type of the variable. > For example there are not compiling: > int x = 0.5; > int y = 0; > y = y + 0.5; > These are no strange for me. > Although the thing that > int x = 0; > x += .5; > compiles without an error or warning it was unexpected for me. I do not see the usecase for the implicit cast there. (BTW the result I got was the correct 0 .) > Maybe it is just me who finds this strange. Without the implicit cast to the left hand side type, "+=" could not have been used for byte, char, or short. The arithmetic operation promotes to int, and there would be no way to cast back to the target type. If the assignment and the arithmetic are done by separate operators, the right hand side of the assignment can be explicitly cast to the left hand side type if that is what is meant. Patricia