Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #3964

Re: Java puzzler

Date 2011-05-11 05:24 -0700
From Patricia Shanahan <pats@acm.org>
Newsgroups comp.lang.java.programmer
Subject Re: Java puzzler
References <4db69c13-878f-4806-adb2-a3c5adb1c48c@glegroupsg2000goo.googlegroups.com>
Message-ID <qrGdnWE1mOKFHVfQnZ2dnUVZ_uKdnZ2d@earthlink.com> (permalink)

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Re: Java puzzler Gábor Bakos <aborgabor@gmail.com> - 2011-05-11 01:44 -0700
  Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-11 05:24 -0700
    Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-11 21:57 +0100
      Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-11 16:07 -0700
        Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-12 21:38 +0100
          Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 13:45 -0700
            Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 16:56 -0400
              Re: Java puzzler markspace <-@.> - 2011-05-12 14:32 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 16:05 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-12 17:40 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:18 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-12 19:26 -0700
                Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-14 10:18 +0100
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-14 08:09 -0700
                Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-14 13:00 -0400
                Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-14 15:08 -0400
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-14 13:25 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-14 08:46 -0700
                Re: Java puzzler Spock <spock@starfleet.ufp> - 2011-05-14 19:33 -0400
                Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 00:41 +0100
                Re: Java puzzler markspace <-@.> - 2011-05-14 18:35 -0700
                Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-14 23:43 -0400
                Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 11:16 +0100
                Re: Java puzzler markspace <-@.> - 2011-05-15 05:40 -0700
                Re: Java puzzler Tom Anderson <twic@urchin.earth.li> - 2011-05-15 15:23 +0100
                Re: Java puzzler markspace <-@.> - 2011-05-15 08:09 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 07:37 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-15 08:00 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 08:16 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 07:35 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-15 08:11 -0700
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-15 08:15 -0700
                Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-15 13:11 -0400
                Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 20:47 -0400
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:00 -0700
                Re: Java puzzler markspace <-@.> - 2011-05-12 18:01 -0700
                Re: Java puzzler Nancy 3 <n3@gmai1.c0m> - 2011-05-12 21:22 -0400
                Re: Java puzzler Patricia Shanahan <pats@acm.org> - 2011-05-12 18:32 -0700
                Re: Java puzzler Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-12 22:34 -0400
              Re: Java puzzler Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-05-12 22:27 -0400
      Re: Java puzzler "John B. Matthews" <nospam@nospam.invalid> - 2011-05-12 00:28 -0400
      Re: Java puzzler Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-05-12 10:33 -0400
  Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:12 -0400
  Re: Java puzzler Lew <noone@lewscanon.com> - 2011-05-11 09:13 -0400
  Re: Java puzzler markspace <-@.> - 2011-05-11 08:00 -0700

csiph-web