Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!news.stack.nl!.POSTED!ipv6.urchin.earth.li!twic From: Tom Anderson Newsgroups: comp.lang.java.programmer Subject: Re: Java puzzler Date: Thu, 12 May 2011 21:38:31 +0100 Organization: Stack Usenet News Service Lines: 33 Message-ID: References: <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com> NNTP-Posting-Host: ipv6.urchin.earth.li Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Trace: mud.stack.nl 1305232712 80867 2001:ba8:0:1b4::6 (12 May 2011 20:38:32 GMT) X-Complaints-To: abuse@stack.nl NNTP-Posting-Date: Thu, 12 May 2011 20:38:32 +0000 (UTC) User-Agent: Alpine 2.00 (DEB 1167 2008-08-23) In-Reply-To: Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:4022 On Wed, 11 May 2011, Patricia Shanahan wrote: f > On 5/11/2011 1:57 PM, Tom Anderson wrote: >> On Wed, 11 May 2011, Patricia Shanahan wrote: > ... >>> 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. >> >> Well, that's true if one takes as given that the operation promotes to >> int. Could it have been specified not to? > > Sure, but that would create other weirdness. For example: > > byte b = 100; > byte c = 100; > int i = b + c; > > would assign -56 to i, because that is the byte result of the addition. Okay, i've changed my mind. Instead, all arithmetic operations, and all casts, should throw an exception if they overflow. Then, if a string of operations does not do anything surprising, the matter of casting is moot, and if they do, they blow up, so it is also moot. tom -- only positivistic reason and the forms of philosophy based on it are universally valid -- Pope Benedict XVI